Program 4.2. Write a program to assist travelers in completing their travel expe
ID: 3825616 • Letter: P
Question
Program 4.2. Write a program to assist travelers in completing their travel expense claim When you travel for business your company will reimburse you for your travel expenses. To be reimbursed, you must submit a claim that specifies the expenses incurred on each day of travel in various categories. For this program, we will have 6 categories: Airfare, Hotel, Breakfast, Lunch, Dinner, and Taxi. You can create a 2-D array to define these categories: chiar category[6][10] Airfare", "Hotel", "Breakfast", "Lunch", "Dinner We will assume that you can travel up to 30 days. You should create a two-dimensional array to store the expenses per day in each category Program Requirement: Prompt the user for the actual number of days traveled For each day, prompt the user for the expenses in each category and store the expenses in your 2-D array. Compute the total expenses per day and store that in another array variable. Compute the total expenses per category and store that in another array variable. Check to see if the sum of the total expenses per day is equal to the sum of the total expenses per category. If not, it should display: Internal error total daily sum does not match total categor This is an internal error because if you implement your program properly, the sums should be equal. These sums equal the expense claim total. Note, since you should be using float to store your costs, you cannot directly compare the two sums as there may be round-off errors when summing floating point numbers. Thus, you need to check that the two sums differ by less than some epsilon. Since we are dealing with money, a reasonable epsilon would be 0.009. Prompt the user to view various aspects of the expense claim including: expense claim total category totals, daily totals, and expense claim details (actual expenses per day ineach category) It should also offer the option to exit. Here are some sample screen shots of the program running (assuming a person is traveling for 2 days with one hotel stay). You can use your own style for the interface but the functionality should be the same.Explanation / Answer
#include <stdio.h>
int main(void) {
int days,i,j,option;
char category[6][10] = {"Airfare", "Hotel", "Breakfast", "Lunch", "Dinner", "Taxi"};
float expense[30][6];
float totalDays[30];
float totalExpense = 0;
float totalCategory[6];
printf("Travel Expense Claim Assistant");
printf(" Enter the number of days of travel");
scanf("%d",&days); //input number of days
for(i=0;i<days;i++)
{
printf(" Enter expenses for Day %d",days);
for(j=0;j<6;j++)
{
printf(" %s : ",category[j]);
scanf("%f",&expense[i][j]);
}
}
do
{
printf(" Select travel expense claim views ");
printf(" 1.Expense claim total");
printf(" 2.Category totals");
printf(" 3.Daily totals");
printf(" 4.Expense claim details");
printf(" 5.Exit");
printf(" Selection : ");
scanf("%d",&option);
switch(option)
{
case 1:
for(i=0;i<days;i++)
{
for(j=0;j<6;j++)
{
totalExpense = totalExpense + expense[i][j];
}
}
printf(" The total travel expense is : $%.2f",totalExpense);
break;
case 2:
printf(" Totals by category");
for(i=0;i<6;i++)
{
totalCategory[i] = 0;
for(j=0;j<days;j++)
{
totalCategory[i] = totalCategory[i] + expense[j][i];
}
}
for(i=0;i<6;i++)
{
printf(" %s %.2f",category[i],totalCategory[i]);
}
break;
case 3:
printf(" Totals by days");
for(i=0;i<days;i++)
{
totalDays[i] = 0;
for(j=0;j<6;j++)
{
totalDays[i] = totalDays[i] + expense[i][j];
}
}
for(i=0;i<days;i++)
{
printf(" Day %d : $%.2f",(i+1),totalDays[i]);
}
break;
case 4:
printf(" Expense claim details: ");
for(i=0;i<days;i++)
{
printf(" Day%d",(i+1));
for(j=0;j<6;j++)
{
printf(" %s : %.2f",category[i],expense[i][j]);
totalExpense = totalExpense + expense[i][j];
}
}
printf(" The total travel expense is : $%.2f",totalExpense);
break;
case 5:break;
default:printf("invalid option");
break;
}
}while(option !=5);
return 0;
}
output:
Travel Expense Claim Assistant
Enter the number of days of travel 2
Enter expenses for Day 2
Airfare : 287.5
Hotel :116.8
Breakfast :8.75
Lunch :18
Dinner :30
Taxi :28.6
Enter expenses for Day 2
Airfare :0
Hotel :0
Breakfast :9.2
Lunch :20
Dinner :29
Taxi :30.25
Select travel expense claim views
1.Expense claim total
2.Category totals
3.Daily totals
4.Expense claim details
5.Exit
Selection :1
The total travel expense is : $578.10
Select travel expense claim views
1.Expense claim total
2.Category totals
3.Daily totals
4.Expense claim details
5.Exit
Selection :2
Totals by category
Airfare 287.50
Hotel 116.80
Breakfast 17.95
Lunch 38.00
Dinner 59.00
Taxi 58.85
Select travel expense claim views
1.Expense claim total
2.Category totals
3.Daily totals
4.Expense claim details
5.Exit
Selection :3
Totals by days
Day 1 : $489.65
Day 2 : $88.45
Select travel expense claim views
1.Expense claim total
2.Category totals
3.Daily totals
4.Expense claim details
5.Exit
Selection :4
Expense claim details:
Day1
Airfare : 287.50
Airfare : 116.80
Airfare : 8.75
Airfare : 18.00
Airfare : 30.00
Airfare : 28.60
Day2
Hotel : 0.00
Hotel : 0.00
Hotel : 9.20
Hotel : 20.00
Hotel : 29.00
Hotel : 30.25
The total travel expense is : $1156.20
Select travel expense claim views
1.Expense claim total
2.Category totals
3.Daily totals
4.Expense claim details
5.Exit
Selection : 5
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.