| |||||||||
![]() |
|
|
«
Previous Thread
|
Next Thread
»
|
Thread Tools | Search this Thread | Display Modes |
|
#1
|
|||
|
|||
|
Loop problem
Hi ,
I have this problem I need to code in C++: we want to know how many candies you can have with a certain amonut of money. Each candy costs $1 and at each candy purchase, you receive 1 coupon. You can redeem 1 candy with 7 coupons. If you have $20, you can have 23 candies. 20/7=2 more candies from the coupons=2 more coupons. then 20%7=6 coupons remain. 6+2=8 coupons with which you can have 1 candy. So 20+2+1=23 candies in total. I try to use the modulo ("%") but still I cannot find the answer. Iwant to use a loop. this what I did. I found 22 bars instead of 23. #include<iostream> using namespace std; int main() { int money,n; int s,finish; cout<<" Enter the total amount of money "; cin>>money; do { s=(money/7)+(money%7); n=money+(money/7); } while(s<7); cout<< "bar "<<n; cout<<endl; cin>>finish;// keep the output window open return 0; } Do you have an idea? Thank you B |
|
#2
|
||||
|
||||
|
__________________
This is my code. Is it not nifty? "The biggest problem encountered while trying to design a system that was completely foolproof, was, that people tended to underestimate the ingenuity of complete fools." ---Douglas Adams Join the Itsacon fanclub! Zero Tolerance: Spammers banned so far: 280
![]() |
![]() |
| Viewing: Dev Articles Community Forums > Programming > C/C++ Help > Loop problem |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|
|
|
|