Question:
Basic level C++ question?
?
2010-02-07 17:29:52 UTC
This is the step of what I'm working on that I just can't seem to get. I can't figure out the code and highly appreciate any help!
"When selecting choice 2 - calculate how many scoops of ice cream (assume 1 scoop = $1.34) the user can afford
First you need to know how much cash the user currently has (ask the user)
Then calculate the number scoops the user can currently afford
This would be easy enough - so try to solve this problem using a while-loop. The basic idea is to keep subtracting the cost of one scoop from the user's current cash amount until that amount is negative. And to keep track of how often the loop iterated."
Three answers:
Kurt
2010-02-07 17:39:20 UTC
I think your problem is with the while loop:



float moneyAmt; <--float so it can contain decimal places

int numScoops = 0; <-- counter



cout<<"How Much Money Do You Have?\n";

cin>>moneyAmt;



while(moneyAmt > 1.34){

moneyAmt-=1.34;

numScoops++;

}



return numScoops;
RaSerJinCA
2010-02-07 17:42:59 UTC
I don't really know how to solve this cause I'm doing C# now, but I just want to point out a few mistakes.



you should use float moneyAmt, since you're dealing with money, which has decimals.



you didn't include any c statements to keep track of the number of loops.



maybe you can add in a print statement like cout<<"A scoup of ice-cream purchased.\n You have $*.** left.\n"



would be good. sorry i can't fully solve your question
?
2010-02-07 19:03:29 UTC
amountofcash/1.34=result, its that simple


This content was originally posted on Y! Answers, a Q&A website that shut down in 2021.
Continue reading on narkive:
Loading...