- 1

Can anyone tell me what's wrong with this code? It supposed to submit value to purchaseAmount variabel 3 times. But why??

#include <iostream> using namespace std; int main() { int purchaseAmount = 0; int totalPrice; do { cin>>purchaseAmount; purchaseAmount++; }while(purchaseAmount <= 3); totalPrice = purchaseAmount*15/100; cout<<totalPrice<<"\n"; return 0; }

3rd Jul 2021, 4:12 AM
FARIZI FATTAH
FARIZI FATTAH - avatar
3 ответов
+ 2
Decimals will be lost if we use integers instead of floats. Also, you need to check your do-while loop again #include <iostream> using namespace std; int main() { int purchaseAmount = 0; int totalPrice; do { cin >> totalPrice; cout << totalPrice * 15.0/100 << endl; purchaseAmount++; } while (purchaseAmount < 3); return 0; }
3rd Jul 2021, 5:22 AM
Simba
Simba - avatar
+ 1
Thanks, Simba!
3rd Jul 2021, 5:51 AM
FARIZI FATTAH
FARIZI FATTAH - avatar
+ 1
#include <iostream> using namespace std; int main() { int purchaseAmount = 0; int totalPrice; int n=1; //your code goes here while (n<=3){ cin >> purchaseAmount; totalPrice = purchaseAmount*15.0/100; cout << totalPrice << endl; n++; } return 0; } can anyone explain me why above code doesn't work?
14th Sep 2021, 3:47 AM
AdityaMaurya
AdityaMaurya - avatar