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.
Day 2: Operators
Day 2: Operators
Sort by
recency
|
3409 Discussions
|
Please Login in order to post a comment
here for rounding you can use Math.round or you can just add 0.5 to total for rounding value like: sout((int)(total + 0.5));
I put it all in one line. That way I wouldn't need to use extra variables. This is in C#.
void solve(double meal_cost, int tip_percent, int tax_percent) { double tip, tax; int total_cost; scanf("%lf", &meal_cost); scanf("%d", &tip_percent); tip = (tip_percent*meal_cost)/100; scanf("%d", &tax_percent); tax = (tax_percent*meal_cost)/100; total_cost = round(meal_cost+tip+tax); printf("%d", total_cost); }
tip = tip_percent * meal_cost / 100 tax = tax_percent * meal_cost / 100 total_bill = meal_cost + tip + tax print(round(total_bill))