C++ code help, I think Iā€™m solving this incorrectly. | Sololearn: Learn to code for FREE!
Novo curso! Todo programador deveria aprender IA generativa!
Experimente uma aula grƔtis
+ 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!!

21st Apr 2021, 11:14 PM
levi riley
levi riley - avatar
3 Respostas
+ 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
22nd Apr 2021, 1:38 AM
Michal Doruch
+ 2
Show us what youā€™ve done so far.
21st Apr 2021, 11:32 PM
Jerry Hobby
Jerry Hobby - avatar
+ 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.
22nd Apr 2021, 12:36 AM
levi riley
levi riley - avatar