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

******************* C Language***************** Using do-while loop Write a prog

ID: 3723372 • Letter: #

Question

******************* C Language*****************

Using do-while loop

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

C Code :

#include<stdio.h> // to use scanf() and printf()

#include<stdlib.h> // declaration of exit(0)

int main()

{

do // do while loop

{

printf(" 1 - Gas Mileage ");

printf("2 - Sales Commision ");

printf("3 - Grade Calculation ");

printf("4 - Quit ");

printf("Enter your choice : ");

int choice;

scanf("%d",&choice); // verifying menu choice of user

int tanks; // for case 1

float totalmiles=0,overallmiles; // for case 1

float gallons; // for case 1

float miles,calculate,totalgallons=0; // for case 1

float payroll; // for case 2

switch(choice)

{

case 1:

printf(" Enter total number of tanks : ");

scanf("%d",&tanks);

while(tanks--)

{

printf(" Enter total miles driven : ");

scanf("%d",&miles);

printf(" Enter total number of gallons used for each tank : ");

scanf("%d",&gallons);

totalgallons=totalgallons+gallons; // for overallmiles

totalmiles=totalmiles+miles; // for overallmiles

calculate=miles/gallons;

printf(" Miles per gallon obtained for each tank : %f",calculate);

}

overallmiles=totalmiles/totalgallons; // for overallmiles

printf(" Overall Miles per Gallon obtained for all tanks : %f",overallmiles);

break;

case 2:

while(1)

{

int employees;

printf(" Enter total number of employees : ");

scanf("%d",&employees);

if(employees>=100)

{

float totalsales; // to calculate payroll

printf("Enter total Sales of the week : ");

scanf("%f",&totalsales);

payroll=totalsales*((12.0)/100.0)+300; // calculating payroll of the week

printf("Payroll for the week : %f",payroll*employees);

}

else

break;

}

break;

case 3:

case 4:

exit(0);

}

}while(1);

}