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
Who was the father of computer?????​
adell [148]

Answer:

Charles Babbage

Explanation:

4 0
3 years ago
Read 2 more answers
What are the differences between a cursor, insertion point and mouse pointer?​
Anna35 [415]

Answer:

Explanation:

A cursor is a pointer which indicates the position of the mouse on a computer's display monitor.

An insertion point is a location in a document where additional information is inserted when the user begins to type.

A mouse pointer is an image used to activate/control certain elements in a GUI (graphical user interface).

I know you asked for the differences, though i thought I'd add a similarity. All of these 3 things are similar, as they show where the position of the info/mouse is. :)

Hope this helps!

-Biscuit08

7 0
2 years ago
I need help solving this problem on Picoctf. The question is What happens if you have a small exponent? There is a twist though,
soldi70 [24.7K]

Explanation:

Explanation:

RSA encryption is performed by calculating C=M^e(mod n).

However, if n is much larger than e (as is the case here), and if the message is not too long (i.e. small M), then M^e(mod n) == M^e and therefore M can be found by calculating the e-th root of C.

5 0
3 years ago
Which of these might be an example of an advertiser's target group?
d1i1m1o1n [39]

Answer:

I would assume C. because it's the answer that makes the most sense.

Explanation:

D. would be the other choice however, just because they live in the same region doesn't mean they watch TV or have any access to media.

5 0
4 years ago
Read 2 more answers
What data does Bittorrenting uses? Explain.
amid [387]

Answer:

A BitTorrent software consumer utilizes that data into the torrent data to communicate special tracker and support shifting of that data among networks including either complete or incomplete representations about the data-set.

Explanation:

BitTorrent is based at the thought of any torrent, which is a smallish data that includes metadata regarding a host, specific tracker, that organizes the data sharing and data that is distributed. A peer that wants to advance data available need first attain a tracker for the data, generate a torrent and later share the torrent data. Different peers can next use the information included in the torrent file support all other in downloading that data. That download is organized by that tracker.

5 0
3 years ago
Other questions:
  • Write a program that uses a 2-D array to store the highest and lowest temperatures for each month of the year. The program shoul
    14·1 answer
  • Replmon is the first tool you should use when troubleshooting Active Directory replication issues. State True or False.
    12·1 answer
  • Help, please!! A file named "games.txt" exists and has 80 lines of data. You open the file with the following line of code. aFil
    6·1 answer
  • What technique involves graphical methods and nontechnical language that represent the system at various stages of development a
    14·1 answer
  • Shira’s Shoes sold 875,000 pairs of sandals in June, which was 70% of the total number of shoes sold. How many shoes did the com
    14·2 answers
  • Omo help me i need it now.
    12·1 answer
  • JAVA NEED HELP ASAP
    7·1 answer
  • What aspect should you consider before adding pictures to a document?
    6·1 answer
  • I have a problem with my Nintendo DS lite does anyone know how to fix it?
    8·1 answer
  • Programming Cycle. Arrange them in correct order​
    5·2 answers
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!