+ 2

Problem: Who doesn’t like a discount - practice 17.2 (C++)

Can’t get past this one. Help needed. https://sololearn.com/coach/268/?ref=app My code at the moment is: #include <iostream> using namespace std; int main() { int purchaseAmount = 0; int totalPrice; //your code goes do{ cout << totalPrice /100 *15 <<endl; cin >> totalPrice >>endl; purchaseAmount++; } while (purchaseAmount <=3); return 0; }

29th Sep 2021, 6:09 PM
Astrid Weidner
5 odpowiedzi
+ 3
Astrid Weidner yes! You are very close to solved this... Just do a few more change in your code • you need to execute the loop 3 times so remove the = from while(purchaseAmount<=3); • define your variables as double instead of int
29th Sep 2021, 6:51 PM
Saurabh
Saurabh - avatar
+ 3
Can you please attach the problem link in description along with your code link? Astrid Weidner some mistakes I can found by just looking at your code is • you are first printing the value then taking input • remove the ">>endl" in the line where you are taking input. • define your variables as "double" instead of int • also you need to execute the loop 3 times so remove the = from while(purchaseAmount<=3); also I presently I can't access your problem because it's only available for pro members, may any pro member guy or mods will help you out. edit:- bits feature helps me to unlock this problem Regards!
29th Sep 2021, 6:11 PM
Saurabh
Saurabh - avatar
+ 2
Yes, got it. Thanks a lot Sauabh Kumar Yadav. Interestingly i changed the code (int to double) in a place which was given, so I guess sometimes you have to not listen to given intructions or there are several ways of doing things. Anyhow, thanks a lot. For anyone else, this is the way I typed it: #include <iostream> using namespace std; int main() { int purchaseAmount = 0; double totalPrice; //your code goes do{ cin >> totalPrice; cout << totalPrice /100 *15 <<endl; purchaseAmount++; } while (purchaseAmount <3); return 0; }
2nd Oct 2021, 8:18 AM
Astrid Weidner
+ 1
Your code just print all zeros by iterating loop 5 times.. Because you are not taking input or assigning values to totalprice.. What is the task actually, post some description or what task you are trying with this .. (17.2 link may be for pro only).. edit: oh. is that an edit cout to cin in cin>>totalPrice>>endl; or I seen it wrong? may be I read it as cout<<totalPrice<<endl; Any way, take it as first line in loop.. as just cin>>totalPrice;
29th Sep 2021, 6:15 PM
Jayakrishna 🇮🇳
+ 1
Saurabh Kumar Yadav yes, noticed the input and moved it before printing value. Thanks, took away the >>endl from the input line. With these changes it came really close. First time the outcome ”you came close”. This is more confusing, how can it almost be right 🤔 first outcome was wright, second almost and third not so much. By that I mean, there are three input values snd outputs.
29th Sep 2021, 6:31 PM
Astrid Weidner