I am doing a CS50 problem-Half. I did the problem and it kinda worked, but when entering for example:
Bill before tax and tip: 12.50
Sale Tax Percent: 8.875
Tip percent: 20
It outputs $7.80
and not $8.17
.
When entering:
Bill before tax and tip: 100
Sale Tax Percent: 20
Tip percent: 10
It works.
Why is that when giving decimals its wrong and when giving round numbers it works?
#include <cs50.h>
#include <stdio.h>
float half(float bill, float tax, int tip);
int main(void)
{
float bill_amount = get_float("Bill before tax and tip: ");
float tax_percent = get_float("Sale Tax Percent: ");
int tip_percent = get_int("Tip percent: ");
printf("You will owe $%.2f each!\n", half(bill_amount, tax_percent, tip_percent));
}
// TODO: Complete the function
float half(float bill, float tax, int tip)
{
float price;
tax = bill * tax / 100.0;
tip = (bill + tax) * tip / 100;
price = bill + tax + tip;
return price / 2;
}