Need decimal guidance on a pro quiz C++ | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
0

Need decimal guidance on a pro quiz C++

Hello, I am new to C++ and I am going through the lessons but need help figuring out this quiz. On the C++ pro quizzes in the conditional and loops section and subsection “The do... while loop” has a pro quiz called “Who doesn’t love a discount” All my outputs are correct except the first one. In one of the computers Inputs is 6930 where the expected output is 1039.5 but my code only outputs 1039 so it’s marking only that one wrong and all the rest are correct. So I’m missing the .5 and the lessons prior does not explain how to make sure the math goes to the next decimal. Here is the scenario: A supermarket has launched a campaign offering a 15% discount on 3 items. Write a program that takes the total price for every purchase as input and outputs the relevant discount. https://code.sololearn.com/cZRznQHFnElV/?ref=app

9th Dec 2020, 10:32 PM
Brian Nash
Brian Nash - avatar
2 Answers
+ 1
try: #include <iomanip> and cout << setprecision(2); Also you need to use float (or double); Have they given an example input and output?
9th Dec 2020, 11:13 PM
rodwynnejones
rodwynnejones - avatar
+ 1
Thank you. What worked from what you told me was double. The lessons did not go over those yet so i did a google search on how to use double. So i used it inplace of my int variable and it works. All are correct now. Thank you again!
9th Dec 2020, 11:53 PM
Brian Nash
Brian Nash - avatar