This thing is pushing me around. I've been through my book, and I have even downloaded the professor's notes on subject (he posted them). I can't find what I'm doing wrong. Below is the code I've written, below the code is what the console is "supposed" to look like.
(Code begins here):
#include <iostream> #include <fstream> #include <iomanip> using namespace std; int main() { int price, amountpaid; float change; cout << "Please give the price of the item (example: $5.95).\n"; cin >> price; while (price > 0.00) { cout << "Please enter the amount you wish to pay\n"; cin >> amountpaid; if (amountpaid <=0) { cerr << "Invalid input, program closing\n"; exit (1); } if (amountpaid < price) { cout << " You still owe " << price - amountpaid << " dollars "; } if (amountpaid >=0) change= amountpaid-price; cout << " You will recieve " << change << " dollars in change." << endl; exit (1); } return 0; }
(Code ends here)
For some reason I cannot put any number with a decimal in for "price" or "amountpaid". Also, The change is supposed to show up as WHAT change is being recieved, example:
1 Ten
2 Fives
0 Ones
2 Quarters
0 Dimes
0 Nickels
1 Penny
No matter what I've tried to do, I can't get farther than the above code. Can anyone help me?
Note: I've understood that somehow, "modulo" operators are needed here. But I haven't the foggiest idea how to use them! Can anyone, with great detail, tell me how I could use them here?