We use cookies to ensure you have the best browsing experience on our website. Please read our cookie policy for more information about how we use cookies.
Thats weird, my code passed passed all test cases except for the last one, and the printf("the total cost is %.0f dollars",round(total_cost)); allowed to pass the last test case.
Not sure why though. Can someone explain why the code I wrote didnt pass the last case, because im not seeing why that is.
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
The code i wrote for the total cost is the following, this didnt pass the last case:
totalCost is of type float.
cout<<"The total meal cost is "<< round(totalCost) <<" dollars."<
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
The code i wrote entirely is the following:
void solve(double meal_cost, int tip_percent, int tax_percent) {
float totalCost;
double tip,tax;
//Calculating Tip %
tip = meal_cost * (tip_percent/100.0);
//Calculating Tax %
tax = meal_cost * (tax_percent/100.0);
//Calculating Total Cost $
totalCost = meal_cost + tip + tax;
printf("The total meal cost is %.0f dollars.",round(totalCost));
//cout<<"The total meal cost is "<< round(totalCost) <<" dollars."<<endl;
//This line of code didnt pass 'Testcase 3'
Day 2: Operators
You are viewing a single comment's thread. Return to all comments →
Thats weird, my code passed passed all test cases except for the last one, and the printf("the total cost is %.0f dollars",round(total_cost)); allowed to pass the last test case. Not sure why though. Can someone explain why the code I wrote didnt pass the last case, because im not seeing why that is. ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ The code i wrote for the total cost is the following, this didnt pass the last case: totalCost is of type float.
cout<<"The total meal cost is "<< round(totalCost) <<" dollars."<
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ The code i wrote entirely is the following:
void solve(double meal_cost, int tip_percent, int tax_percent) { float totalCost; double tip,tax;
} ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~