Sunday, August 2, 2009

Another question about my c++ program i dont know what wrong with it?

i dont know what do cout at the end so i just couted amount i think its wrong. plzzz help.


#include %26lt;conio.h%26gt;// needed for getch


#include %26lt;iostream.h%26gt;//needed for cout and cin messages


#include %26lt;string.h%26gt;//needed for string copy


#include %26lt;iomanip.h%26gt;


#include %26lt;math.h%26gt;


void startup();


void method();


int main()


{


startup();


method();


getch();


return 0;


}





void startup()


{


cout%26lt;%26lt;""%26lt;%26lt;'\n';


cout%26lt;%26lt;"jan 14, 2008"%26lt;%26lt;'\n';


cout%26lt;%26lt;"pg pro"%26lt;%26lt;'\n';


cout%26lt;%26lt;""%26lt;%26lt;'\n';


}


void method()


{


float amount, quaters=0, dimes=0, pennies=0, nickels=0;








cout%26lt;%26lt;"Enter amount of money less than $1: $ ";


cin%26gt;%26gt;amount;





quaters = amount / 25;


amount = quaters * 25;





dimes = amount / 10;


amount = dimes * 10;





pennies = amount / 1;


amount = pennies * 1;





nickels = amount / 5;


amount = nickels * 5;





cout%26lt;%26lt;"Your amount divided is: "%26lt;%26lt;amount%26lt;%26lt;'\n';


}

Another question about my c++ program i dont know what wrong with it?
If you are requesting the amount in the form of 0-99 you should enter it into an integer. You can then use the mod operator to accomplish what you need.





quarters=amount/25;


amount=amount%25;





dimes=amount/10;


amount=amount%10;





etc.
Reply:So that we can know what you are trying to do, please put comments in your program. Also please tell us what you are entering and what is coming out. THe way it is written, what comes out should be the same as what you put in, since you restore "amount" over and over.


-------------


OK, since you want to print out the number of quarters, etc, then print out the quarters, not the amount. In other words,





cout %26lt;%26lt; "The number of quarters is " %26lt;%26lt; quarters%26lt;%26lt;"\n";





and so on for the other types of coins.


No comments:

Post a Comment