I am having problems with my code. For example when I execute my code and type 1 in the one goes to coin return when it should go into the slot. I can't figure out what's wrong with my code. Any help would be extremely appreciated seeing as how the program is due tomorrow.
Here is the code:
Here is the code:
Rich (BB code):
#include<iostream>
#include <conio.h>
#include <iomanip> //use for setw
using namespace std;
int main()
{
int intnum, quarters, dimes, nickels;
double decnum, money, slot=0.00, coinreturn=0.00;
bool flag=true;
do
{
// setprecision(2) so that the 0.00 will appear in the executable.
cout << setprecision(2) << fixed;
slot=0.00;
coinreturn=0.00;
do
{
system("cls");
cout<<endl;
cout << setw(35) << "ICE COLD COLA";
cout << endl;
cout << setw(33) << ".75 cents";
cout << endl;
cout << endl;
cout <<" Deposit -- dollar, quarters, dimes, or nickels:";
cout << endl;
cout << setw(22) << "( 1" << " ," << setw(6)<< " .25" << " ,"
<< " .10" << " ," << setw(8) << " .05" << " )";
cout << endl;
cout << endl;
cout << setw(16) << "Slot"<<" [" << slot <<" ]" <<" :";
cout << endl;
cout << endl;
cout << endl;
cout << endl;
cout << setw(14) << "Coin Return" <<" [" << coinreturn <<" ]" <<" :";
cout << endl;
cout << endl;
cout << setw(10) << " Enter Coin" << "[" << "------" <<"]" << " ";
cin>> money;
cout<<endl<<endl;
/* makes it so that when .05, .10, .25, and $1.00 is entered into the
machine the money will be added together and shown in the slot
Any amount of money that is not equal to .05, .10, .25, and $1.00
will be placed in the coin return.
*/
if (money == 1.00 || money == 0.25 || money == 0.10 || money == 0.05)
slot += money;
else
coinreturn += money;
}while(slot <= .75 && money != -1);
cout<<" Here is your Cola!"<<endl<<endl<<endl;
cout<<" Have a nice day!"<<endl;
decnum = (slot - .75);
//use static_cast to convert a double into an integer
intnum = static_cast<int>((decnum +.005) * 100);
quarters = intnum/25;
intnum = intnum%25;
dimes = intnum/10;
intnum = intnum%10;
nickels = intnum/5;
intnum = intnum%5;
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;
system("pause");
}while(money != -1);
cout<<endl<<endl<<endl;
}