How to write a program that calculates mileage reimbursement for a salesperson at a rate of $.45 per mile. The program should interact with the user in this manner:MILEAGE REIMBURSEMENT...

How to write a program that calculates mileage reimbursement for a salesperson at a rate of $.45 per mile. 

The program should interact with the user in this manner:
MILEAGE REIMBURSEMENT CALCULATOR
Enter beginning odometer reading=> 13505.2
Enter ending odometer reading=> 13810.6
You traveled 305.4 miles. At $0.45 per mile,
your reimbursement is $137.43.

Asked on by aneele99

1 Answer | Add Yours

tiburtius's profile pic

tiburtius | High School Teacher | (Level 2) Educator

Posted on

The program:

#include<stdio.h>
int main()
{
float b,e;
printf("Enter beginning odometer reading=>");
scanf("%f",&b);
printf("\nEnter ending odometer reading=>");
scanf("%f",&e);
printf("\nYou traveled %.2f. At $0.45 per mile, your reimbursement is %.3f.",e-b,(e-b)*0.45);
return 0;
}

You could also allow the user to input price per mile by adding these two lines:

printf("\nEnter price per mile=>");
scanf("%f",&p);

also you would have to change the last printf to

printf("\nYou traveled %.2f. At $%f per mile, your reimbursement is %.3f.",e-b,p,(e-b)*p);

Of course you would have to add p to line 4 of the original code.

We’ve answered 318,991 questions. We can answer yours, too.

Ask a question