Question

In: Computer Science

develop an algorithm and then a C program that accomplishes the following. determines the minimum number...

  • develop an algorithm and then a C program that accomplishes the following.
    • determines the minimum number of quarters, dimes, nickels, and pennies to make change for any amount of cents from 1 cent to 99 cents inclusive;
    • produces an error message if 0 or more than 99 is entered as input, but the program will keep running and ask for another input;
    • terminate if 0 or a negative number is entered.
    • Here is possible example of the program running (remember that there could be any number of inputs (perhaps 1,000,000) but all inputs are integers)

Hints: use if / else if / else... use % and /... use a while loop or a do while loop, no arrays

example:

Please enter the number of cents, from 1 through 99, or enter a negative number to quit:  31
             Quarters: 1   Dimes: 0   Nickels: 1   Pennies: 1

               Please enter the number of cents, from 1 through 99, or enter a negative number to quit:  89
               
Quarters: 3 Dimes: 1 Nickels: 0 Pennies: 4
               Please enter the number of cents, from 1 through 99, or enter a negative number to quit:  121
   Your entered a value outside the range.

               Please enter the number of cents, from 1 through 99, or enter a negative number to quit:  0
   Your entered a value outside the range.
               
Please enter the number of cents, from 1 through 99, or enter a negative number to quit:  18
               Quarters: 0 Dimes: 1 Nickels: 1 Pennies: 3
   Your entered a value outside the range.

               Please enter the number of cents, from 1 through 99, or enter a negative number to quit:  -666   
               Thanks for using my program. Good bye.

Solutions

Expert Solution

program:

#include <stdio.h>
#include <stdlib.h>
int main()
{
        int amount; /* how much change the user has */
    int leftover; /* used to hold amount as it decreases */
    int numquarters; /* how many quarters */
    int numdimes; /* how many dimes */
    int numnickels; /* how many nickels */
    int numpennies; /* how many pennies */

    /* read in the amount and save it */
    printf("Please enter the number of cents, from 1 through 99, or enter a negative number to quit:");
    scanf("%d", &amount);
    while(amount>=0)
    {
       if(amount == 0 || amount>99)
       {
           printf("Your entered a value outside the range.\n");
       }
       else
       {
           leftover = amount;
           /* computer the number of quarters and how much is left over */
           numquarters = leftover / 25;
           leftover = leftover % 25;
           /* computer the number of dimes and how much is left over */
           numdimes = leftover / 10;
           leftover = leftover % 10;
           /* computer the number of nickels and how much is left over */
           numnickels = leftover / 5;
           leftover = leftover % 5;
           /* whatever is left over is the number of pennies */
           numpennies = leftover;
           /* print the result */
           printf("Quarters: %d Dimes: %d Nickels: %d Pennies: %d\n", numquarters, numdimes, numnickels, numpennies);
       }
       printf("Please enter the number of cents, from 1 through 99, or enter a negative number to quit:");
       scanf("%d", &amount);
   }
   printf("Thanks for using my program. Good bye.");
}

output:


Related Solutions

develop an algorithm and then a C program that accomplishes the following. determines the minimum number...
develop an algorithm and then a C program that accomplishes the following. determines the minimum number of quarters, dimes, nickels, and pennies to make change for any amount of cents from 1 cent to 99 cents inclusive; produces an error message if 0 or more than 99 is entered as input, but the program will keep running and ask for another input; terminate if 0 or a negative number is entered. Here is possible example of the program running (remember...
Develop an algorithm and implement Optimal Page Replacement algorithm using C++. Determine the number of page...
Develop an algorithm and implement Optimal Page Replacement algorithm using C++. Determine the number of page faults and page hits by considering the Frame size=4, ReferenceString:2 4 6 7 8 2 4 9 13 9 2 7 2 6 1 4 9 2
Create a basic program (C Programming) that accomplishes the following requirements: Prints "for loop" and then...
Create a basic program (C Programming) that accomplishes the following requirements: Prints "for loop" and then uses a for statement to count from 1 to 100. Prints "while loop" and then uses a while statement to count from 1 to 100. Prints "do while loop" and then use a do while statement to count from 1 to 100. Using a nested if/else statement or a switch in one of the loops , print to the screen if a number is:...
Prime Number Determines if a number is prime or not I also need the algorithm and...
Prime Number Determines if a number is prime or not I also need the algorithm and pseudocode in java.
Create a basic program (C programming language) that accomplishes the following requirements: Allows the user to...
Create a basic program (C programming language) that accomplishes the following requirements: Allows the user to input 2 numbers, a starting number x and ending number y Implements a while loop that counts from x (start) to y(end). Inside the loop, print to the screen the current number Print rather the current number is even or odd If the number is even , multiply by the number by 3 and print the results to the screen. If the number is...
Write a C++ program for Euclids Algorithm that keeps track of the number of iterations (%...
Write a C++ program for Euclids Algorithm that keeps track of the number of iterations (% & loop) 1. Euclid’s Algorithm An alternative of the Euclidean algorithm for finding greatest common divisors (GCD) is repeatedly performing the modulo operation on two numbers until the remainder is 0. Here is the pseudocode for find the GCD of two positive numbers a and b using the Euclidean algorithm :while b ≠ 0 temp = b b = a mod t a =...
write a c++ program Find an algorithm and show the codes for evaluating the number of...
write a c++ program Find an algorithm and show the codes for evaluating the number of numbers between 200 and 1000 that are divisible by 2 and 7
Programming language: C++   suggested software: Code::Blocks Develop an algorithm and write a C++ program that computes...
Programming language: C++   suggested software: Code::Blocks Develop an algorithm and write a C++ program that computes the final score of a baseball game. Use a loop to read the number of runs scored by both teams during each of nine innings. Display the final score afterward. Submit your design, code, and execution result via file, if possible
Write a C++ program that finds the minimum number entered by the user .The user is...
Write a C++ program that finds the minimum number entered by the user .The user is allowed to enter negative numbers 0, or positive numbers. The program should be controlled with a loop statement. Break statements is not allowed to break from loop. After each number inputted by the user, The program will prompt user if they need to enter another number. User should enter either Y for yes or N for no. Make Sure the user enters either Y...
Write a program in C language that uses a binary search algorithm to guess a number...
Write a program in C language that uses a binary search algorithm to guess a number from 1 to 100. The computer will keep guessing until they get the users number correct.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT