Problem here. I assume that I put too many nested if and else statements and screwed up somewhere :x. Anyway, the project is:
Write a program to print the coins necessary to return change to a customer after a purchase. The change can be made up of quarters, dimes, nickels and pennies. You may assume that the amount of change is less than $1. Your program should use the minimum number of coins needed. Input the amount of change in cents.
Yeah, So I've been at this for a while and came up to the conclusion that I suck at programming. Help would be greatly appreciated.
I get no value for Quarters (q) and everything else says its equal to 0 in the output.
Code:#include <iostream.h> #include <conio.h> main() { int q1, d1, n1, p1, ans, change; int q=0; int d=0; int n=0; int p=0; do { cout << "What is the change amount? "; cin >> change; if (change>25) do { q1=change-25; q++; change=change-(q*25); } while(q1>=25); else if (change>10) do { d1=change-10; d++; change=change-(d*10); } while (d1>=10); else if (change>5) do { n1=change-5; n++; change=change-(n*5); } while (n1>=5); else if (change>1) do { p1=change-1; p++; change=change-(p*1); } while (p1>=1); else cout << "Amount of quarters " << q << '\n'; cout << "Amount of dimes " << d << '\n'; cout << "Amount of nickels " << n << '\n'; cout << "Amount of pennies " << p << '\n'; cout << "\nTry again? (1 = yes, 2 = no): "; cin >> ans; } while (ans=1); return 0; }



LinkBack URL
About LinkBacks
.


