+ 1
C++ code help, I think I’m solving this incorrectly.
In c++ practice lesson 18.2 am I meant to solve the problem by using a double instead of the int it gave me? At that point I have not learned them yet but am told that’s the only way? Any suggestions on other ways to solve I’m kinda stumped and feel like I’m missing something from that lesson and a little bit of insight would go a long way. -thanks in advance!!
4 Réponses
+ 1
You have to divide by 100.0, cuz 15/100 is always 0.
If you divide integers, result will always get rounded to lower value (100/15=0.15≈0)
Or just multiply by 0.15
+ 2
Show us what you’ve done so far.
+ 1
#include <iostream>
using namespace std;
int main()
{
int purchaseAmount = 0;
double totalPrice;
//your code goes here
do{cin>>totalPrice;
totalPrice=totalPrice*15/100;
cout<<totalPrice<<endl;
purchaseAmount++;}
while(purchaseAmount<=2);
return 0;
}
This is the answer that i gave and was correct, however, i had to change int totalPrice into double totalPrice. And at this point nothing in the course taught me about a double.