Please help me write these two programs using C sentinel whi

Please help me write these two programs using C++ sentinel while loop.

Drivers are concerned with the mileage obtained by their automobiles. One driver has kept track of several thankful of gasoline by recording miles driven and gallons used for each tankful. Develop a C++ program that uses a while structure to input the miles driven and gallons used for each tankful. The program should calculate and display the miles per gallon obtained for each tandful. After processing all input information, the program should calculate and print the combined miles per gallon obtained for all tanfuls. Your output screen should somewhat look like the following: Enter the gallons used (-1 to end): 12.8 Enter the miles driven: 287 The miles/gallon for this tank was 22.421875 Enter the gallons used (-1 to end): 10.3 Enter the miles driven: 200 The miles/gallon for this tank was 19.417475 Enter the gallons used (-1 to end): 5 Enter the miles driven: 120 The miles/gallon for this tank was 24.0000 Enter the gallons used (-1 to end): -1 The overall average miles/gallon was 21.601423 2. Using a while loop statement and if statements to write a program that can be used at a department store\'s register that records the number of customers who spent between $0.00 - $200.00, $200.01 - $800.00, $800.01 or more At the end of a day, the program will print out the number of customers in each of categories.

Solution

While loop we check till -1entered by user.

Please find below code for the same.

int main()
{
     /*Initialize all the variables to zero*/
     float gallons, miles, tot_Gallons = 0.0;
   float tot_Avg = 0.0;
   float tot_Miles = 0.0;
   /* Prompt the user for number of gallons (user will enter –1 to end entries)*/
   printf (\"Enter gallons used (-1 to end): \");
    scanf (\"%f\", &gallons);
/* While the number of gallons is not -1*/
   while (gallons != -1)
   {
       /* Add number of gallons to tot_Gallons */
       tot_Gallons += gallons;
     /* Prompt user to enter number of miles driven */
       printf (\"Enter number of miles driven: \");
        scanf (\"%f\",&miles);
       /*Add number of miles driven to total number of miles driven*/
         tot_Miles += miles;
        /* Calculate and print miles per gallon for current tank */
         printf (\"The miles per gallon for this tank was %f\", miles/gallons);
         /* Prompt user for number of gallons */
         printf (\"\ Enter the gallons used (-1 to end):\");
        scanf (\"%f\", &gallons);
    }
      /* If tot_Gallons is not zero*/
     if (tot_Gallons != 0)
      {
         /* Calculate total average as tot_Miles/tot_Gallons*/
         tot_Avg = tot_Miles/tot_Gallons;
       /*Print tot_Avg to screen*/
        printf (\"\ The overall average miles per gallon was %f \ \", tot_Avg);
    }
    else
     /* If no gallons entered give error message to user*/
       printf (\"No gallons were entered\ \");

    return 0;
}

Please help me write these two programs using C++ sentinel while loop. Drivers are concerned with the mileage obtained by their automobiles. One driver has kept

Get Help Now

Submit a Take Down Notice

Tutor
Tutor: Dr Jack
Most rated tutor on our site