//cents
#include <iostream>
using std::cout;
using std::cin;
using std::endl;
#include <conio.h>
int main ()
{
double a, b , c, d, e;
double total;
total = (.50*a) + (.20*b) + (.10*c) + (.05*d) + (.01*e);
cout<<"\tFifty cents? ";
cin>> a,
cout<<"\n\tTwenty cents? ";
cin>> b,
cout<<"\n\tTen cents? ";
cin>> c,
cout<<"\n\tFive cents? ";
cin>> d,
cout<<"\n\tOne cents? ";
cin>> e,
cout<<"\n\tYour Total is: Php " << total << endl;
getch();
return 0;
}
result:
Fifty cents? 3
Twenty cents? 2
Ten cents? 1
Five cents? 2
One cents? 3
Your Total is: Php 4.51831e-303
i dont understand why the printed total is different when in fact
if you would just calculate using the given variables the answer
would only be 2.13
The compiler reads from top to bottom. So in line 15, variables a, b, c, d, and e aren't set to any values. It doesn't remember that total = blah blah blah when you tell it to display the total. Put line 15 after cin >> e; like QWERTYman said, when a, b, c, d and e have values.