well I did this but doesn't work, when I run it If I put 2.50 for the price it wont run but if I just put 2 it will ask for the amount paid so I don't know whats going on.
#include <iostream>
#include <string>
#include <iomanip>
usingnamespace std;
int main()
{
string firstname;
string lastname;
string price;
string paid;
int amountprice;
int amountpaid;
int change=0;
int dollar=0;
int quarters=0;
int dimes=0;
int nickels=0;
int cents=0;
cout << "Please enter your first name"<< endl;
cin>>firstname;
cout << "Please enter your last name"<< endl;
cin>> lastname;
cout << " Welcome "<< firstname << " " << lastname << endl;
cout<< "In this program we will see the amount money that is needed to be paid and the change that will be do" << endl;
//ask user to enter the price and how much money they paid
cout<<" Please enter the price of the object: $"<< setprecision(2) << fixed << price << endl;
cin>>amountprice;
cout<<" Enter the amount that you paid: $"<< setprecision(2) << fixed << paid << endl;
cin>>amountpaid;
if (amountprice>amountpaid)
{
cout<<"You didnt pay the full amount, pay the full amount or return the item"<<endl;
return -1;
}
change = amountpaid - amountprice;
cout << "The change for this transaction is: $" << setprecision(2) << fixed << change << endl;
change = change*100;
dollar = change/100;
quarters=change/25;
change=change -(quarters *25);
dimes=change/10;
change=change-(dimes*10);
nickels=change/5;
change=change-(nickels*5);
cents=change;
cout << "Dollars: " << dollar << endl;
cout << "Quarters: " << quarters << endl;
cout << "Dimes: " << dimes << endl;
cout << "Nickels: " << nickels << endl;
cout << "Cents: " << cents << endl;
cout << endl;
return 0;
}
At the end of line 25, it should be "due" not "do". You also left out the period.
You're missing an apostrophe in "didn't" in line 35. Line 35 is also a comma-splice.
#include <iostream>
#include <string>
#include <iomanip>
usingnamespace std;
int main()
{
string firstname;
string lastname;
string price;
string paid;
double amountprice;
double amountpaid;
double change;
double dollar=0.0;
double quarters=0.0;
double dimes=0.0;
double nickels=0.0;
double cents=0.0;
cout << "Please enter your first name"<< endl;
cin>>firstname;
cout << "Please enter your last name"<< endl;
cin>> lastname;
cout << " Welcome "<< firstname << " " << lastname << endl;
cout<< "In this program we will see the amount money that is needed to be\
paid and the change that will be due" << endl;
//ask user to enter the price and how much money they paid
cout<<" Please enter the price of the object: $" << endl;
cin>>amountprice;
cout<<" Enter the amount that you paid: $"<< endl;
cin>>amountpaid;
if (amountprice>amountpaid)
{
cout<<"You didn't pay the full amount, pay the full amount or return \
the item"<<endl;
return -1;
}
cout << "The change for this transaction is: $"<< endl;
change=amountpaid - amountprice;
change = change*100;
dollar = change/100;
//change=change%100;
quarters=change/25;
//change=change%25;
dimes=change/10;
//change=change%10;
nickels=change/5;
//change=change%5;
cents=change;
cout << "Dollars: " << dollar << endl;
cout << "Quarters: " << quarters << endl;
cout << "Dimes: " << dimes << endl;
cout << "Nickels: " << nickels << endl;
cout << "Cents: " << cents << endl;
cout << endl;
return 0;
}
this is what I get if I am to run it but its not entirely right and im not getting the change for example the change for this transaction is 1.50
Please enter the price of the object: $
1.50
Enter the amount that you paid: $
3.00
The change for this transaction is: $
Dollars: 1.5
Quarters: 6
Dimes: 15
Nickels: 30
Cents: 150