After I enter money paid it just shuts off. I eliminated beg. and end to fit. Help please. I see it showing... on a couple of lines when I am trying to send but it is not like that. At the end of*********"; Thanks
{
int numCups, numMugs, numCookies;
double total, paid, change;
cout%26lt;%26lt;"Enter number of cups of hot chocolate: ";
cin%26gt;%26gt;numCups;
cout%26lt;%26lt;"Enter number of mugs of hot chocolate: ";
cin%26gt;%26gt;numMugs;
cout%26lt;%26lt;"Enter number of cookies: ";
cin%26gt;%26gt;numCookies;
cout%26lt;%26lt;endl;
total = numCups * cups + numMugs * mugs + numCookies * cookies;
cout.setf(ios::fixed);
cout.setf(ios::showpoint);
cout.precision(2);
cout%26lt;%26lt;"Amount due = $ ";
cout%26lt;%26lt;total%26lt;%26lt;endl;
cout%26lt;%26lt;endl;
cout%26lt;%26lt;"Enter amount of money paid: ";
cin%26gt;%26gt;paid;
cout%26lt;%26lt;"********************";
cout%26lt;%26lt;"Merry Mary's Hot Chocolate Stand Bill"%26lt;%26lt;endl;
cout%26lt;%26lt;endl;
cout%26lt;%26lt;"Cups of Hot Chocolate\n";
cout%26lt;%26lt;"Number = "%26lt;%26lt;numCups;
C++ simple I/O prog Execution terminates ???
Of course, you can use doubles with streams!
And no need to initialize them either - they are initialized when they are read in.
Try adding missing %26lt;%26lt;endl after the "****", and at the last line (the cout is line-buffered, so, it may not be printing stuff out until it sees the end of line - that would explain why you don't see the last line in the output).
Also, cups, mugs and cookies variables are not declared anywhere... but that cannot be your problem - it just would not
copile if it was - so, you must have them declared somewhere, and just not included into the snippet.
Other than that, there doesn't seem to be anything wrong with your program.
Reply:Declare paid as int, you can't use a double with cin.
If you need to do some calculation with doubles you can force cast, for example:
total = double(paid/numCups);
In this case, the cocient is forced to be delivered double
Good luck!
Reply:Try initializing the double values in the beginning.
double total=0, paid=0, change=0;
Or see if you get any errors if you use float instead of double?
It shows ......... because yahoo answers has a limit on how many characters you can have in one word.
imwriting thissentencewithoutspacesseethedotsinthe...
Thats the only suggestion I can give you at this point. Sorry
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment