Feb 12, 2008 at 2:29am UTC
I cant get this code to work when i dont put the zeros in for the int it gives random values and when i do put them in they come up as zero
so i want to know if i should use the zeros and if not what is the problem without them
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37
#include<iostream>
using namespace std;
int main(){
float Money = 0.00;
int Money1 = 0000;
int Pennies = 00000;
int Nickles = 000;
int Dimes = 00;
int Quarters = 0;
cout << " Welcome to the Money Counter " << endl;
cout << "Type in the amount: " ;
cin >> Money;
Money = Money * 100;
Money = Money1;
cout << endl << endl << endl;
if (Money1 >= 25){
Quarters = (Money1/25);
Money1 = Money1 - (25*Quarters) ;
}
if (Money1 < 25 && Money1 >= 10){
Dimes = (Money1/10);
Money1 = Money1 - (10 * Dimes);
}
if (Money1 < 10 && Money1 >= 5){
Nickles = (Money1/5);
Money1 = Money1 - (5 * Nickles);
}
if (Money1 < 5 && Money1 >= 1){
Pennies = Money1;
}
cout << " That is " << Quarters << " Quarters " << Dimes << " Dimes " << Nickles <<
" Nickles " << Pennies << " Pennies " << endl;
system("PAUSE" );
return 0;
}
Last edited on Feb 12, 2008 at 2:30am UTC
Feb 12, 2008 at 2:35am UTC
If you are talking about the initial values for Money1, Pennies, Nickles, Dimes, and Quarters--it is compiler based. It is best to always initialize your variables to a certain value or else the computer will give it some random value which could be whatever is stored in the memory at that location. To ensure you start with a clean slate giving your variables initial values is the surefire way to go.
I hope this answers your question.
Feb 12, 2008 at 2:44am UTC
i figured that out thank you for conferming it for me, but ther is still a problem with the program it returns all zeros
(running with Dev-C++ compiler)
Last edited on Feb 12, 2008 at 2:45am UTC