Ce diaporama a bien été signalé.
Le téléchargement de votre SlideShare est en cours. ×

Write a complete C program to calculate change as follows- The user s.docx

Publicité
Publicité
Publicité
Publicité
Publicité
Publicité
Publicité
Publicité
Publicité
Publicité
Publicité
Publicité

Consultez-les par la suite

1 sur 2 Publicité

Write a complete C program to calculate change as follows- The user s.docx

Télécharger pour lire hors ligne

Write a complete C program to calculate change as follows: The user should enter the amount the customer owes and the amount of money the customer paid. The program should calculate and display the amount of change, as well as, how many dollars, quarters, dimes, nickels and pennies to return to the customer. Always assume that the customer paid either the exact amount or more than the exact amount. Use functions to get input from the user and to display the output. Only input and output are to be written using functions!
Solution
#include <stdio.h>
void calChange(int remainingAmount)
{
// Find the number of one dollars
int numberOfOneDollars = remainingAmount / 100;
remainingAmount = remainingAmount % 100;
// Find the number of quarters in the remaining amount
int numberOfQuarters = remainingAmount / 25;
remainingAmount = remainingAmount % 25;
// Find the number of dimes in the remaining amount
int numberOfDimes = remainingAmount / 10;
remainingAmount = remainingAmount % 10;
// Find the number of nickels in the remaining amount
int numberOfNickels = remainingAmount / 5;
remainingAmount = remainingAmount % 5;
// Find the number of pennies in the remaining amount
int numberOfPennies = remainingAmount;
// Display results
printf(\"*****Your change****\ \");
printf(\"%d dollars\ \",numberOfOneDollars);
printf(\"%d quarters\ \",numberOfQuarters);
printf(\"%d dollars\ \",numberOfDimes);
printf(\"%d nickels\ \",numberOfNickels);
printf(\"%d pennies\ \",numberOfPennies);
}
int main()
{
float amt;
printf(\"Enter the amount in cents: \");
scanf(\"%f\",&amt);
int remainingAmount = (amt * 100);
calChange(remainingAmount);
return 0;
}
.

Write a complete C program to calculate change as follows: The user should enter the amount the customer owes and the amount of money the customer paid. The program should calculate and display the amount of change, as well as, how many dollars, quarters, dimes, nickels and pennies to return to the customer. Always assume that the customer paid either the exact amount or more than the exact amount. Use functions to get input from the user and to display the output. Only input and output are to be written using functions!
Solution
#include <stdio.h>
void calChange(int remainingAmount)
{
// Find the number of one dollars
int numberOfOneDollars = remainingAmount / 100;
remainingAmount = remainingAmount % 100;
// Find the number of quarters in the remaining amount
int numberOfQuarters = remainingAmount / 25;
remainingAmount = remainingAmount % 25;
// Find the number of dimes in the remaining amount
int numberOfDimes = remainingAmount / 10;
remainingAmount = remainingAmount % 10;
// Find the number of nickels in the remaining amount
int numberOfNickels = remainingAmount / 5;
remainingAmount = remainingAmount % 5;
// Find the number of pennies in the remaining amount
int numberOfPennies = remainingAmount;
// Display results
printf(\"*****Your change****\ \");
printf(\"%d dollars\ \",numberOfOneDollars);
printf(\"%d quarters\ \",numberOfQuarters);
printf(\"%d dollars\ \",numberOfDimes);
printf(\"%d nickels\ \",numberOfNickels);
printf(\"%d pennies\ \",numberOfPennies);
}
int main()
{
float amt;
printf(\"Enter the amount in cents: \");
scanf(\"%f\",&amt);
int remainingAmount = (amt * 100);
calChange(remainingAmount);
return 0;
}
.

Publicité
Publicité

Plus De Contenu Connexe

Similaire à Write a complete C program to calculate change as follows- The user s.docx (20)

Plus par lez31palka (20)

Publicité

Plus récents (20)

Write a complete C program to calculate change as follows- The user s.docx

  1. 1. Write a complete C program to calculate change as follows: The user should enter the amount the customer owes and the amount of money the customer paid. The program should calculate and display the amount of change, as well as, how many dollars, quarters, dimes, nickels and pennies to return to the customer. Always assume that the customer paid either the exact amount or more than the exact amount. Use functions to get input from the user and to display the output. Only input and output are to be written using functions! Solution #include <stdio.h> void calChange(int remainingAmount) { // Find the number of one dollars int numberOfOneDollars = remainingAmount / 100; remainingAmount = remainingAmount % 100; // Find the number of quarters in the remaining amount int numberOfQuarters = remainingAmount / 25; remainingAmount = remainingAmount % 25; // Find the number of dimes in the remaining amount int numberOfDimes = remainingAmount / 10; remainingAmount = remainingAmount % 10; // Find the number of nickels in the remaining amount int numberOfNickels = remainingAmount / 5; remainingAmount = remainingAmount % 5; // Find the number of pennies in the remaining amount int numberOfPennies = remainingAmount; // Display results printf("*****Your change**** "); printf("%d dollars ",numberOfOneDollars); printf("%d quarters ",numberOfQuarters);
  2. 2. printf("%d dollars ",numberOfDimes); printf("%d nickels ",numberOfNickels); printf("%d pennies ",numberOfPennies); } int main() { float amt; printf("Enter the amount in cents: "); scanf("%f",&amt); int remainingAmount = (amt * 100); calChange(remainingAmount); return 0; }

×