You are asked to write a simple C program that will accept an integer value in the range of 5-95 and in increments of 5 at a time, representing the number of cents to give to a customer in their change. The program should calculate how many coins of each denomination and display this to the user. Valid coin values are 50, 20, 10 and 5. Your solution (program and algorithm) should be modular in nature. This requires the submission of a high-level algorithm and suitable decompositions of each step.

Question
Asked Dec 16, 2019
49 views

You are asked to write a simple C program that will accept an integer value in the range of 5-95 and in increments of 5 at a time, representing the number of cents to give to a customer in their change. The program should calculate how many coins of each denomination and display this to the user. Valid coin values are 50, 20, 10 and 5. Your solution (program and algorithm) should be modular in nature. This requires the submission of a high-level algorithm and suitable decompositions of each step.

check_circle

Expert Answer

Step 1

Program:

/*Header files*/

#include <stdio.h>

#include<stdlib.h>

/* Funtion for taking user unput */

int GetInput()

{

    int num;

    printf("\nEnter an integer value for the number of cents to give to a customer in their change: ");

    scanf("%d", &num);

    return (num);

}

/* Function to check for negative number */

void negative(int userinput)

{

    if(userinput<0)

    {

        printf("The exit/termination of the program.");

        exit(0);

    }

}

/* Funtion for varifing user unput */

void checkinput(int *userinput)

{

    if ((*userinput < 5) || (*userinput > 95) || (*userinput%5 > 0))

    {

        printf("An integer value should be in the range of 5-95 with values being in multiples of 5.\n");

        *userinput = GetInput();

        negative(*userinput);

    }

}

/* Function for Calculate coin denominations */

void Change (int *userinput, int *fifty, int *twenty, int *ten, int *five)

{

    int number = *userinput;

    *fifty = number/50;

    number =number%50;

    *twenty = number/20;

    number =number% 20;

    *ten = number/10;

    number =number%10;

    *five = number/5;

    number =number%5;

    return;

}

/* Display function */

void Display (int *userinput, int *fifty, int *twenty, int *ten, int *five)

{

    printf("%d of cents to give to a customer in their change: \n", *userinput);

        if (*fifty > 1)

            printf(" Fifty cent: %d\n", *fifty);

        if (*fifty == 1)

            printf(" Fifty cent: %d\n", *fifty);

        if (*twenty > 1)

            printf(" Twenty cent: %d\n", *twenty);

        if (*twenty == 1)

            printf(" Twenty cent: %d\n", *twenty);

        if (*ten > 1)

            printf(" Ten cent: %d\n", *ten);

        if (*ten == 1)

            printf(" Ten cent: %d\n", *ten);

        if (*five > 1)

            printf(" Five cent: %d\n", *five);

        if (*five == 1)

            printf(" Five cent: %d\n", *five);

}

/* Main function */

int main()

{

    //Declared int type varible

    int userinput, fifty, twenty, ten, five;

    //Calling GetInput()

    userinput = GetInput();

    //Calling negative()

    negative(userinput);

    //Calling checkinput()

    checkinput(&userinput);

    //Calling Change()

    Change(&userinput, &fifty, &twenty, &ten, &five);

    //Calling display()

    Display(&userinput, &fifty, &twenty, &ten, &five);

    return(0);

}

Step 2

Output #1:

help_outline

Image Transcriptionclose

Enter an integer value for the number of centa to give to a cuatomer in their change: 93 An integer value should be in the range of 5-95 with values being in multiples of 5. Enter an integer value for the number of cents to give to a customer in their change: 90 90 of cents to give to a customer in their change: Fifty cent: 1 Twenty cent: 2

fullscreen
Step 3

Output #2:

...
help_outline

Image Transcriptionclose

Enter an integer value for the number of cents to give to a customer in their change: 75 75 of cents to give to a cuatomer in their change: Fifty cent: 1 Twenty cent: 1 Five cent: 1

fullscreen

Want to see the full answer?

See Solution

Check out a sample Q&A here.

Want to see this answer and more?

Solutions are written by subject experts who are available 24/7. Questions are typically answered within 1 hour.*

See Solution
*Response times may vary by subject and question.
Tagged in

Engineering

Computer Science

Related Computer Science Q&A

Find answers to questions asked by student like you
Show more Q&A
add
question_answer

Q: Please help with the follow question in C++

A: Program Instructions:Create a function insertOnTheTop() that makes a new node and assign that node t...

question_answer

Q: What are strings in c++?

A: String in C++:String is a class found in the library of C++. String object is used to store the stri...

question_answer

Q: What are different inbuilt string functions?

A: The programming language C/C++ has many predefine inbuild string function that requires to include s...

question_answer

Q: Odd even Challange Python Coding Tell user to input a 3 digital number ONLY Use a WHILE LOOP to ask ...

A: Following is the python program that takes as input from user a number and makes sure a number is a ...

question_answer

Q: Write one Python statement to start and continue a while loop while variable name is not an empty st...

A: While loop:With the while loop, if a condition is valid, we may execute a series of statements.Synta...

question_answer

Q: What is the difference between hexanumber and ascii code

A: Warm-up description –ASCII code –ASCII stands for American Standard Code for Information Interchange...

question_answer

Q: Create a complex query based on two or more tables (SCHOOL, DEPARTMENT, PROFESSOR, TECHNOLOGY, COURS...

A: Query:SELECT A.SCHOOL_CODE, a.DEPARTMENT_ID FROM SCHOOL A WHERE A.DEPARTMENT_ID = (SELECT DEPARTMENT...

question_answer

Q: Question 5 and 7

A: Following questions ask to print the recursive function of the two arguments:Declaring the variable ...

question_answer

Q: Im working on homework and am stuck. I have created the code for taking the input of the user but I ...

A: Create a class named MainClassDeclare 2 dimensional array of students which contains 10 students, ea...