Hey guys, I have a soda machine program assignment that requires the user to insert an amount that has to equal to dollars, quarters, dimes, or nickels. Any other input will be displayed in the "Coin Return". The display should loop showing the current amount deposited until the user's deposit is greater than or equal to .75. An entry of "-1" will turn off the machine. My question is when I input .25 three times (which is .75) it breaks out of the loop and doesn't update the slot amount total. Also, when I enter a number larger than what it will take (dollars,quarters,etc.), let's say 25, instead of adding it to the Coin Return, it doesn't accept it and just refreshes. My teacher told me I can use a boolean, but I don't know exactly where or how to do it. Other than that, I am basically finished with the program. If anyone can please help me, I would appreciate it a lot. Here's what I have so far:
#include<iostream>
#include<conio.h>
using namespace std;
int main()
{
int ichange, quarters, dimes, nickels, pennies;
double insert, dchange, CoinReturn=0.00, total=0.00;
bool flag=true;
do
{
CoinReturn=0.00;
total=0.00;
do
{
system("cls");
cout<<endl;
cout<<" ICE COLD COLA "<<endl;
cout<<" Only .75 cents! "<<endl<<endl;
cout<<" Deposit -- dollar, quarters, dimes, or nickels:"<<endl;
cout<<" ( 1 , .25 , .10 , .05 )"<<endl<<endl;
cout<<" Slot" <<": ["<< total <<"]"<<endl<<endl;
cout<<" Coin Return"<<": ["<< CoinReturn <<"]"<<endl<<endl;
cout<<" Enter coin [------] ";
cin>> insert;
cout<<endl<<endl;
if(insert!=1 && insert!=.25 && insert!=.10 && insert!=.05)
CoinReturn=insert;
else
if(flag)
total+=insert;
if(total>=.75)
{
cout<<" Here is your Cola!"<<endl<<endl<<endl;
cout<<" Have a nice day!"<<endl;
break;
}
}while(insert<=.75 && insert!=-1);
dchange=total-.75;
while(dchange>0)
{
ichange = static_cast<int>((dchange +.005) * 100);
quarters = ichange/25;
ichange = ichange%25;
dimes = ichange/10;
ichange = ichange%10;
nickels = ichange/5;
ichange = ichange%5;
pennies = ichange/1;
cout<< endl<< endl<< " Your change is: " <<endl;
cout<<"\t"<< quarters <<" Quarter(s)"<<endl;
cout<<"\t"<< dimes <<" Dime(s)"<<endl;
cout<<"\t"<< nickels<< " Nickel(s)"<<endl;
cout<<"\t"<< pennies <<" Penny(ies)"<<endl<<endl;
break;
}
system("pause");
}while(insert != -1);
cout<<endl<<endl;
}