How to write a C Program to Count Change Program in C Programming Language ?
- #include <stdio.h>
- #include <math.h>
- int main(int argc, const char * argv[]) {
- float total, lecoins, change;
- int quarters, dimes, nickels, pennies;
- printf("How much change are you owed?");
- scanf("%f", &change);
- if (change <= 0) {
- printf("Invalid constant, try again:");
- scanf("%f", &change);
- }
- lecoins = (int) round(change * 100);
- do{ //nested do-while loop.
- while (lecoins >= 25) {
- lecoins = lecoins - 25;
- quarters++;
- total++;
- }
- while (lecoins >= 10) {
- lecoins = lecoins - 10;
- dimes++;
- total++;
- }
- while (lecoins >= 5) {
- lecoins = lecoins - 5;
- nickels++;
- total++;
- }
- while (lecoins >= 1) {
- lecoins = lecoins - 1;
- pennies++;
- total++;
- }
- }
- while (lecoins!=0); {
- printf("\n");
- }
- printf("Quarters: %i \n Dimes: %i \n Nickels: %i \n Pennies: %i\n Total: %f \n", quarters, dimes, nickels, pennies, total);
- return 0;
- }
Learn More :
Count
- C Program String - Alphabet Count Example
- C Program String Count Example
- Write the procedure , which is one of a sum , a product and a geometric average in the panel for the NxM elements are located on opposite diagonal and main diagonal . Remind ! Counting only odd elements !
- C Program Array NxM Elements Geometric/Arithmetic
- C Program to Count Number of Lines in Input until Interrupted by CTRL + Z
- Returns: array of decoded values. [0] - count of values
- Max count of chars, Max count of nums and Max count of signs
- C Program to Count Vowels, Consonants and Spaces in a string
- C Program to count number of sentences words and letters in a paragraph
- Un-sortiertes Array and Sortiertes Array
- LED ON OFF For One Sec/Count and Display on the Attached Serial Monitor
- Menu driven program in C which performs the following operations on strings
- C program to accept n number from user,store these numbers into an array & count the no of occurrences of each number