C++ question about adding integers.?

WE dont determine what i here’s doing wrong with this particular.i am tied to the down payment because should the program needs me that will enter just how much i want it shows me an overall of your wrong final result.for example merely insert 2 of the 5 pennies and 0 on the others the result will often be 2 euros! y it had been supposed to be 10 pennies.

#include
using namespace an std;

int main()

char decision;
two bottle a = 0.05;
two bottle b = 0.EIGHT;
two bottle c = 0.50;
two bottle d = A SINGLE.00;
two bottle total;

cout << "Welcome to be able to my Piggy Bank\n"<<endl;

cout << "\tMenu" << endl;
cout << "=====================\n" << endl;
cout<<" I highly recommend you enter a new choice\n" << endl;
cout<<" n:Deposit"<< endl;
cout<<" w:Withdraw"<< endl;
cout<<" s:Show total"<< endl;
cout<<" e:Empty"<< endl;
cout<<" queen:Quit\n"<< endl;

cin>>choice;

change (choice)
case ‘d’:
cout<<" Deposit"<<endl;
crack;
case’w’:
cout<<"Withdraw"<<endl;
crack;
case’s’:
cout<<"Show total"<<endl;
crack;
case ‘e’:
cout<<"Empty"<<endl;
crack;
case ‘q’:
cout<<"Quit"<<endl;
crack;

if (choice == ‘d’)

cout << "Number with 5 cents:";
cin >> the;

cout << "Number with 10 cents:";
cin >> b;

cout << "Number with 50 cents:";
cin >> c;

cout << "Number with 1 euro:";
cin >> n;

cout <<endl;

full = a + b + d + ve had;

cout << "PiggyBank possesses "<< whole << " Euros" << endl;

procedure (“pause”);
go back 0;

Hope this can do

Inside total,
full = a + b + d + ve had;
you happen to be adding many of the cents and euro’s together as one unit

As a result, you need to…

full = a*0.05 + b*0.ONE + c*0.A FEW + d*1

Inside variable a new 5 pennies is saved, b EIGHT cents are generally stored, c 50 cents are saved, d YOU euro can be stored.

Therefore 5 cents = 0.05 Euros, EIGHT cents = 0.ONE Euros, 50 cents =.A FEW Euros

Therefore grow them having variables in addition to store them in total to obtain the overall Euros

As an alternative to double, its better for you to define any, b, c, d, since Integers,

#include
using namespace an std;

int main()

char decision;
int the, b, c, d;
two bottle total;

cout << "Welcome to be able to my Piggy Bank\n"<<endl;

cout << "\tMenu" << endl;
cout << "=====================\n" << endl;
cout<<" I highly recommend you enter a new choice\n" << endl;
cout<<" n:Deposit"<< endl;
cout<<" w:Withdraw"<< endl;
cout<<" s:Show total"<< endl;
cout<<" e:Empty"<< endl;
cout<<" queen:Quit\n"<< endl;

cin>>choice;

change (choice)
case ‘d’:
cout<<" Deposit"<<endl;
crack;
case’w’:
cout<<"Withdraw"<<endl;
crack;
case’s’:
cout<<"Show total"<<endl;
crack;
case ‘e’:
cout<<"Empty"<<endl;
crack;
case ‘q’:
cout<<"Quit"<<endl;
crack;

if (choice == ‘d’)

cout << "Number with 5 cents:";
cin >> the;

cout << "Number with 10 cents:";
cin >> b;

cout << "Number with 50 cents:";
cin >> c;

cout << "Number with 1 euro:";
cin >> n;

cout <<endl;

full = a*0.05 + b*0.ONE + c*0.A FEW + d*1;

cout << "PiggyBank possesses "<< whole << " Euros" << endl;

procedure (“pause”);
go back 0;

Thank you, Hope the item helps

You happen to be welcome,

You’re definitely not doing any kind of math aside from adding that inputs along.You’ll should write a few functions to convert the amount of money up coming from 5 pennies to 15 cents, 50 cents, and also 1 euro.

Leave a Reply