Thread: calculating change with the basic commands

1. calculating change with the basic commands

I need some small help hopefully. I thought i could figure this out on my own but obviously since i am posting to this board for the first time, well you know.

I am trying to get this program to calculate change tendered by breaking it down by dollars, half-dollars, quarters, dimes, nickels, and pennies. Reliaze this is just the beginning of the class so not allowed to use loops, modulus, etc.. this is why i am stuck.

Code:
```#include <iostream>// cin, cout, <<, >>
using namespace std;

int main()
{
cout << "Enter the amount of purchase" <<"\n";
double purchaseAmt;
cin >> purchaseAmt;
cout << "Enter your payment amount given" <<"\n";
double paymentAmt;
cin >> paymentAmt;
double changeAmt = paymentAmt - purchaseAmt;
cout << "\nYour change back is:   " << changeAmt << "\n";
double halfDollar = changeAmt / .50;
double quarters = changeAmt / .25;
double dimes = changeAmt / .10;
double nickels = changeAmt / .5;
double pennies = changeAmt;
cout << "\nhalfDollar back:  " << halfDollar << "\n";
cout << "\nQuarters back:  " << quarters << "\n";
cout << "\nDimes back:   " << dimes << "\n";
cout << "\nNickels back:  " << nickels << "\n";
return 0;
}```

2. God why are all you guys never giving info ? What is wrong ? What is your question ? What have you tried ? What's your compiler ? Give us some meat to work on, dude.

Basically what you have to do is divide the payment amount by the highest unit and go down to cents. So let's say you divide by 1.00 dollar then by .25 dollar, then .10 dollar, then .05 dollar and finally .01 dollar. Each time you divide, you have to substract the answer of the division to the payment amount.

Code:
```int dollars = (int)paymentAmt; // Same as 'paymentAmt / 1.00'
paymentAmt -= dollars;
int quarters = paymentAmt / 0.25;
paymentAmt -= quarters * 0.25;
// ...```
Or something like this. Haven't compiled.