- 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; }
3 Réponses
+ 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;
}
+ 1
Thanks, Simba!
+ 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?