Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Write a program using a menu to execute the following: Menu 1 – Gas Mileage 2 –

ID: 3723164 • Letter: W

Question

Write a program using a menu to execute the following:

Menu 1 – Gas Mileage

2 – Sales Commission

3 – Grade Calculation

4 - Quit Verify the menu choice is 1, 2, 3, or 4

The program should continue to loop until the user selects 4 to quit. For the Gas mileage part of the problem.

Menu 1 - Drivers are concerned with the mileage obtained by their automobiles. One driver has kept track of several tanks of gasoline by recording miles driven and gallons used for each tank. Develop a program using a while loop that will input the miles driven and the gallons used for each tank. The program should calculate and display the miles per gallon obtained for each tank. After processing all input information, the program should calculate and print the overall miles per gallon obtained for all tanks.

Menu 2- People in sales frequently earn a base salary and commission on their sales. A company has asked you to write a program to estimate the payroll for the week given a person’s sales. The sales force earns a base salary of $300 per week plus 12% of their total sales for the week. Since each department has a different number of employees, use a while loop to allow the user to exit the program by entering an employee number less than 100 when they have completed.

Explanation / Answer

#include <stdio.h>

int main(void) {
int choice;
double milesDriven,gallonsUsed,milesPerGallon,avgMPG,sales,salaryPerWeek;
int empNo,count;;
count = 0;


do
{
printf(" 1 – Gas Mileage");
printf(" 2 – Sales Commission");
printf(" 3 – Grade Calculation");
printf(" 4 - Quit");
printf(" Enter your choice : ");
scanf("%d",&choice);
if(choice == 4)
break;
switch(choice)
{
case 1: // calcuating miles per gallon for all trucks and overall mpg
   printf(" Enter the miles driven : ");
    scanf("%lf",&milesDriven);
   while(milesDriven != 0)
   {
   
    printf(" Enter the gallons used : ");
    scanf("%lf",&gallonsUsed);
    milesPerGallon = milesDriven/gallonsUsed;
    printf(" Miles Per Gallon : %lf",milesPerGallon);
    avgMPG = avgMPG + milesPerGallon;
    count++;
    printf(" Enter the miles driven : ");
    scanf("%lf",&milesDriven);
   }
   printf(" Overall miles per gallon for all tanks : %lf",avgMPG/count);
  
   break;
case 2: // calculating salary per week of employees
   printf(" Enter employee number : ");
   scanf("%d",&empNo);
   while(empNo > 100)
   {
    printf("Enter the sales for the person : ");
    scanf("%lf",&sales);
    salaryPerWeek = 300+ sales*0.12;
    printf(" Salary per week : %lf",salaryPerWeek);
    printf(" Enter the employee number : ");
    scanf("%d",&empNo);
   
   }
case 3: break;
case 4: break;
default : printf(" Invalid choice ");
   break;
   }
}
while(choice != 4);
return 0;
}

Output:

1 – Gas Mileage
2 – Sales Commission
3 – Grade Calculation
4 - Quit
Enter your choice :1
Enter the miles driven :34
Enter the gallons used :6.7
Miles Per Gallon : 5.07463
Enter the miles driven :66
Enter the gallons used :9
Miles Per Gallon : 7.33333
Enter the miles driven :0
Overall miles per gallon for all tanks : 6.20398
1 – Gas Mileage
2 – Sales Commission
3 – Grade Calculation
4 - Quit
Enter your choice :2
Enter employee number :101 Enter the sales for the person :4567
Salary per week : 848.04
Enter the employee number : 102 Enter the sales for the person :6775
Salary per week : 1113
Enter the employee number :90
1 – Gas Mileage
2 – Sales Commission
3 – Grade Calculation
4 - Quit
Enter your choice : 4

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote