+ 1

Please why does my code not work properly

You sell souvenir kaleidoscopes at a gift shop, and if a customer buys more than one, they get a 10% discount on all of them! Given the total number of kaleidoscopes that a customer buys, let them know what their total will be. Tax is 7%. All of your kaleidoscopes cost the same amount, 5.00. Task: Take the number of kaleidoscopes that a customer buys and output their total cost including tax and any discounts. Input Format: An integer value that represents the number of kaleidoscopes that a customer orders. Output Format: A number that represents the total purchase price to two decimal places. https://code.sololearn.com/c9aWroM3R4Gb/?ref=app

8th Jan 2023, 10:35 PM
Theophilus
Theophilus - avatar
6 Respuestas
+ 1
I updated the question with the code please
9th Jan 2023, 8:49 AM
Theophilus
Theophilus - avatar
+ 1
Theophilus As HAPPY TO HELP wrote, one error is that you must first apply (subtract) the discount before calculating and adding on the tax. You will also find that there will be two other small errors when you test it in Code Coach, one is already being reported in the console (a return error) which you can see in code playground (run the code in your Code Bits). You are very close! Try again and then if you still have any other questions just ask.
10th Jan 2023, 5:06 AM
Scott D
Scott D - avatar
0
Thank you very much Scott D and Happy To Help for the fixes. It's not fully working in code coach but it works in my own compiler
10th Jan 2023, 8:53 AM
Theophilus
Theophilus - avatar
0
Theophilus But have you tested it in code coach? The results of your output are currently incorrect. With an input of 3 the result should be 14.45, your code does not produce that, unless you have updated a code that is not the one linked. The issue is not with the compiler - I made a few small changes to your code, tested it in the Community Code Coach and it passed no problem. Ignoring the errors from the Code Coach is not a good solution, some compilers are more forgiving and do not report all errors.
10th Jan 2023, 9:30 AM
Scott D
Scott D - avatar
0
I've updated the code with what I submitted to the code coach but I keep failing test case 2 and 5. My code still gives me 14.45 instead of 14.45
10th Jan 2023, 10:04 AM
Theophilus
Theophilus - avatar
0
#include <iostream> using namespace std; double kaleidoscpoes(int x){ x*=5; return (x<6)?x+x*.07:(x-x*.1)+(x-x*.1)*.07; } int main() { int input; cin >> input; printf("%.2f",kaleidoscpoes(input)); } If you want to output via cout cout. precision(your number after dot) , but I recommend for beginners using printf for float and double numbers. Keep learning..
10th Jan 2023, 12:04 PM
Smith Welder
Smith Welder - avatar