1answer.
Ask question
Login Signup
Ask question
All categories
  • English
  • Mathematics
  • Social Studies
  • Business
  • History
  • Health
  • Geography
  • Biology
  • Physics
  • Chemistry
  • Computers and Technology
  • Arts
  • World Languages
  • Spanish
  • French
  • German
  • Advanced Placement (AP)
  • SAT
  • Medicine
  • Law
  • Engineering
Cloud [144]
3 years ago
15

help users calculate their car miles per gallon. write a program to allow a user to enter the number of miles driven and the num

ber of gallons of gas used. the output should be the miles per gallon. use a Do... while (post-test) loop to allow users to enter as many sets of data as desired.
Computers and Technology
1 answer:
Tpy6a [65]3 years ago
8 0

Answer:

The c++ program for the scenario is given below.

#include <iostream>

using namespace std;

int main() {    

   float miles, gallon, speed;

   char reply;    

   cout<<"This program calculates speed of your car in miles per gallon." <<endl;    

   do

   {

       do

       {

           cout<<endl<<"Enter the miles driven by your car" <<endl;

           cin>>miles;

           if(miles<=0)

           {

               cout<<"Invalid input. Enter the miles driven by your car."<<endl;

               cin>>miles;

           }            

       }while(miles<=0);        

       do

       {

           cout<<"Enter the gallons of gas used by your car" <<endl;

           cin>>gallon;

           if(gallon<=0)

           {

               cout<<"Invalid input. Enter the gallons of gas used by your car."<<endl;

               cin>>gallon;

           }

       }while(gallon<=0);    

       speed = miles/gallon;

   

       cout<<"Your car drives at "<<speed<<" miles per gallon."<<endl;        

       cout<<"Do you with to continue (y/n)?"<<endl;

       cin>>reply;        

   }while(reply != 'n');    

   return 0;

}  

This program calculates speed of your car in miles per gallon.

Enter the miles driven by your car

0

Invalid input. Enter the miles driven by your car.

-9  

Enter the miles driven by your car

12.34

Enter the gallons of gas used by your car

0

Invalid input. Enter the gallons of gas used by your car.

-2

Enter the gallons of gas used by your car

3.4

Your car drives at 3.62941 miles per gallon.

Do you with to continue (y/n)?

n

Explanation:

The do while loop is also known as post-test loop. This loop executes once mandatorily. After first execution, the condition is tested and based on the condition, the loop either executes again or discontinues.

In this program, the loop continues till the user wants to try out different sets of data for calculation. Once the user enters input to quit, the loop discontinues.

Do

{  

cout<<"Do you with to continue (y/n)?"<<endl;

        cin>>reply;

}while(reply != 'n');

Moreover, the input by the user is tested for validity. The input cannot be negative or zero. This is implemented by if statement.

if(miles<0)

       {

           cout<<"Invalid input. Miles cannot be negative."<<endl;

           cin>>miles;

       }

The same validity is implemented for gallons of gas also.

You might be interested in
A(n) ________ is a chart based on PivotTable data.
Mrrafil [7]
Well since it’s a chart based on a PivotTable prettyyyy sure it’s gonna be a PibltChart
7 0
2 years ago
An engineer is designing an HTML page and wants to specify a title for the browser tab to display, along with some meta data on
Nady [450]

An HTML is made up of several individual tags and elements such as the head, body. form, frame and many more.

In an HTML page, the meta element and the title element are placed in the head element.

An illustration is as follows:

<em>< head > </em>

<em>< title > My Title < /title ></em>

<em>  < meta charset="UTF-8" > </em>

<em>< / head ></em>

<em />

The head element contains quite a number of elements and tags; some of them are:

  • meta
  • title
  • style
  • script
  • base

And so on.

Hence, in order to use a meta-data element, the meta element has to be placed within the head element.

Read more about HTML elements at:

brainly.com/question/4484498

5 0
3 years ago
How often should you typically monitor your checking account? Yearly Daily Every three months Monthly
Maslowich
I’d say monthly. It probably wouldn’t kill you to do it every three months though.
7 0
3 years ago
Read 2 more answers
Help please! I need help with this question, it’s very hard.
sasho [114]

Answer:

1. PRINTER

2.Proj

3.USB

4.CAM

7 0
3 years ago
Most network cards contain a port that accepts a(n) ____, which looks similar to a telephone connector but is larger.
Vadim26 [7]
YOUR ANSWER IS -------- It accepts a RJ-45 connector
hope i helped you :).
take care
8 0
3 years ago
Other questions:
  • Plz answer and dont put a random thing for the points
    11·1 answer
  • How to get an hdmi working from a chromebook?
    6·2 answers
  • A(n) ____ is a request for specific data from a database.
    9·1 answer
  • When working in the middle of a presentation, how do you preview the slide show from the current slide?
    12·1 answer
  • #include
    9·1 answer
  • Charles would like to visit a specific page on the World Wide Web. How should he do it? Enter the address in a search engine cli
    15·2 answers
  • To prepare a data character for transmission, a ____ bit is added to the beginning of the character and informs the receiver tha
    11·1 answer
  • Use the ________ method to write text to a web page.
    12·1 answer
  • Where can you find the sizing handles for a graphic, shape, or text box? Check all that apply.
    10·2 answers
  • Challenge activity 1.11.1: using constant in expression is not working for me. Can any one help me find the right code?
    12·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!