Alright where to start where to start...
Ah here we go. Well just to let you all know, this is a 2 person GROUP assignment. So it is for a grade (extra credit actually).
I am not asking you guys to DO this work for me. Just more or less try to help me with what is wrong and some simple pointers, that I just haven't really learned to implement correctly. So here goes.
This is the infamous Change program. Where you take the cost of merchandise and then take the amount tendered, and then give change in
I needed to make a function for CHANGE AND INPUT, which I did..
5 dollar bills , dollars, quarters , dimes , nickels, and pennies.
My problems so far. In order of annoyance.
I am not asking for help by one person on all 3 , any info you could point me in would be a great help THanks ahead of time
1)If I dont need a certain coin for change, then I shouldnt list it. So if i need just 2 quarters, it shouldn't say 0 dimes, 0 pennies ect..
I am thinking that i need to somehow put in an if statement or somthing to say : if a value of a coin is zero, dont show it.
Code:
if ((change>=50)&& (change<75))
{
change=change-50;
quarter=quarter+2;
}
My next problem is for some reason it is giving change for the first input (money) instead of the change I have left from subtracting (tendered-money)
Code:
while(money>=0.00)
{
amount=money*100;
dollar=money;
change=(money-dollar)*100;
if (change >= 500)
{
change = dollar/500;
dollar5 = dollar5+1;
}
if(change>=75)
{
change=change-75;
quarter=quarter+3;
}
I have tried switching the variables, but to really no avail...
3)MOST ANNOYING PROBLEM.. I get the program to loop and all that good stuff but I CAN input a dollar AND CHANGE number into the first input ...(money = 1.15), but when I go to input the amount tendered , if I used a whole number it will work. HOwever when I use something like 2.20. It will
A) not give me the correct value and B) SKIP THE NEXT : ENTER COST AND GO STRAIGHT TO THE SECOND INPUT...
I have no idea why..I am sure this is a simple math error but for playing with thing for many many hours.
4 ) I cannot get the 5 dollar bills to show up at all! I know its an error in here. I am multiplying or dividing something wrong...
Code:
amount=money*100;
dollar=money;
change=(money-dollar)*100;
if (change >= 500)
{
change = dollar/500;
dollar5 = dollar5+1;
}
Last thing... In the beggining of the program I USED TO HAVE #include <iostream.h> but later changed it to <iostream> because i had to use <<fixed<< setprecision (2)...could this be a problem also.
I d like to thank anyone that would like to help me out. I know its a lot of reading..but seriously I have been reading these posts /help/ programs you guys write and I am completely amazed by this stuff. I like C++ but since I am a newb its tough.
Almost forgot ..
Code:
#include <iostream>
#include <iomanip>
using namespace std;
void CHANGE();
void input();
int quarter,dime,penny,dollar, nickel, amount, dollar5, tendered;
double money, change, totalchange;
int main()
{
dollar=dollar5=quarter=dime=penny=nickel=0.00;
input();
CHANGE();
while(money>=0.00)
{
amount=money*100;
dollar=money; //problems here!!
change=(money-dollar)*100;
if (change >= 500)
{
change = dollar/500;
dollar5 = dollar5+1;
}
if(change>=75)
{
change=change-75;
quarter=quarter+3;
}
if ((change>=50)&& (change<75))
{
change=change-50;
quarter=quarter+2;
}
if((change>=25)&&(change<50))
{
change=change-25;
quarter=quarter+1;
}
if((change>=10)&&(change<25))
{
change=change-10;
dime=dime+1;
}
if(change>=10)
{
change=change - 10;
dime=dime+1;
}
if((change>=5)&&(change<10))
{
change=change-5;
nickel+=1;
}
if((change<5))
{
penny=penny+change+0.01;
}
cout<<endl;
CHANGE();
cout << fixed << setprecision(2) << " The change is:" << totalchange;
cout << "."<<endl;
cout << dollar5 <<" Five Dollars" << endl;
cout << dollar<<" Dollar"<<endl;
cout << quarter<<" Quarter"<<endl;
cout << dime<<" Dime"<<endl;
cout << nickel<<" Nickel"<<endl;
cout << penny<<" Penny"<<endl<<endl;
dollar5=dollar=quarter=dime=nickel=penny=tendered=0.00; // DO i need this???
input();
CHANGE();
}
return 0;
}
void CHANGE()
{
totalchange = (tendered - money);
}
void input()
{
cout << " Enter -1 to exit the program"<<endl;
cout << " Enter cost of purchase :";
cin >> money;
cout << endl;
cout << " Enter amount tendered :";
cin >> tendered;
}