fork download
  1. #include <iostream>
  2. using namespace std;
  3.  
  4. // Function Prototypes.
  5. int NormalizeMoney(int);
  6.  
  7. int main()
  8. {
  9. int dollars; // Number of dollars in change
  10. int cents=0; // Amount of change
  11. int amount=1; // Amount counter
  12.  
  13.  
  14. cout << "Enter the amount of cents you wish to calculate.\n";
  15. cout << "Enter 0 when finished.\n";
  16. cout << "Enter amount of cents would you like to calculate: ";
  17. cin >> cents;
  18. dollars = NormalizeMoney(cents);
  19.  
  20. while (cents!=0)
  21. {
  22. amount+=cents;
  23. amount++;
  24. cout << "Enter amount of cents would you like to calculate: ";
  25. cin >> cents;
  26. dollars = NormalizeMoney(cents);
  27. }
  28. return 0;
  29. }
  30. int NormalizeMoney (int cents)
  31. {
  32. double dollars=0;
  33. // Convert cents to dollars and cents.
  34. dollars = ((float)cents/100);
  35. cents = cents - (dollars*100);
  36. cout << "The Converted Amount is $" << dollars << endl;
  37.  
  38.  
  39.  
  40. static float sum=0; // Local static variable.
  41. // Accumulate a Running Total.
  42. sum+=dollars;
  43. // Display Sum.
  44. cout << "The Current Sum is: " << sum << endl;
  45.  
  46. return dollars;
  47. }
Success #stdin #stdout 0s 3344KB
stdin
99
187
0
stdout
Enter the amount of cents you wish to calculate.
Enter 0 when finished.
Enter amount of cents would you like to calculate: The Converted Amount is $0.99
The Current Sum is: 0.99
Enter amount of cents would you like to calculate: The Converted Amount is $1.87
The Current Sum is: 2.86
Enter amount of cents would you like to calculate: The Converted Amount is $0
The Current Sum is: 2.86