I am trying to compute amount of change in quarters, nickels,dimes,etc. I have done the program and it runs fine--when no while loop is placed. Everytime I try to change to while loop it sends me into an infinite loop.
here is my program:
#include <iostream>
using namespace std;
int main (void)
{
float price, amount_given,dollars_back;
int change,quarters, dimes,nickels,pennies;
cout<<"Enter price of item: ";
cin>>price;
cout<<"Enter amount given: ";
cin>>amount_given;
dollars_back=amount_given-price;
change=(int)(dollars_back*100); //exact number of cents
cout<<"The change should be: "<<change<<"\n";
I don't understand where you want to put the while loop. I'm not sure if it would be appropriate to put a while loop to replace the calculations for quarters/dimes/nickels/pennies etc, because each of these is calculated a different way (i.e. there's no simple repetition here). Can you post your code with your attempted while loop? Alternatively, can you put what you're trying to achieve into pseudo-code?