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
The data set monarch from Computer-Active Data Analysis by Lunn andMcNeil (1991) contains the years lived after inauguration,ele
gulaghasi [49]

Answer:

0.033

Explanation:

Please kindly check attachment for the step by step solution of the given problem.

5 0
4 years ago
An adiabatic capillary tube is used in some refrigeration systems to drop the pressure of the refrigerant from the condenser lev
kap26 [50]

Answer:

The quality of refrigerant is 0.423

Explanation:

  • Adiabatic tubes drop the pressure from condenser level to evaporator level in refrigeration systems.
  • The values taken in this problem are from the saturated R-134a table.
  • All the calculation is attached in the image. In the problem, hf stands for the enthalpy of saturated liquid while hfg stands for enthalpy of saturated evaporation.
  • Both terms have units KJ/kg (kilo joule per kg).

8 0
4 years ago
Two friends are eating dinner at a restaurant. The bill comes in the amount of 47.28 dollars. The friends decide to split the bi
Daniel [21]

Answer:

bill = 47.28

tip = bill * 0.15

total_pay = bill + tip

each_share = total_pay / 2

print("Each person needs to pay: " + str(each_share))

Explanation:

*The code is in Python.

Set the bill

Calculate the tip, multiply the bill by 0.15

Calculate the total_pay, add bill and tip

Calculate each friend's share, divide the total_pay by 2. Then, print it in required format.

4 0
3 years ago
Can you help me to write a code with functions,arrays,and pointers in c++?
MrMuchimi

Answer:

Your search for complete and error-free projects in C and C++ ends here! Here, we’ve enlisted all the mini-projects, projects, games, software and applications built using C and C++ programming language — these are the projects published in our site or available with us at the moment. You can download all these projects (with source code) for free; make sure to check their individual post description as well.

First thing, most students learn C and C++ as their first programming language. They quickly become able to write programs that include functions, arrays and pointers, file handling and data structure, etc. But, when it comes to building a mini-game, an application, or a small project, incorporating all these features in one compact program becomes difficult.

In such case, reference projects always come in handy. The C and C++ projects published in our site will teach you how to get started, give you ideas and topics regarding your project, and sharpen your programming skills in C and C++. Here, you’ll find short and simple as well as long and complicated projects.

3 0
3 years ago
1) Type a statement that gets an input value into variable numBers. Assume scnr already exists and numBers has been declared.
Sergio039 [100]

Answer:

Following are the code in the java language  

numBers = scnr.nextInt ( ) ;

Here scnr is an instance of scanner class .

Explanation:

In this code, we take the input by using the object of Scanner class i.e "scnr". The scanner class in the java programming language is used for taking the input by the user. The scnr.nextInt ( )  is taking the input which is stored in the  "numbers" variable.

So the whole program is looking like that  

import java.util.*; // import package  

public class Main

{

public static void main(String[] args) // main function

{

 int numBers; // variable declaration

 Scanner scnr=new Scanner(System.in); // create the instance of scanner class

 numBers=scnr.nextInt( ) ; // taking input

 System.out.println(numBers); // display the value of numBers

}

}

Output:

78

78

4 0
3 years ago
Other questions:
  • PLEASE FILL IN THE BLANK FOR THESE POINTS!!!!!
    15·2 answers
  • How do I upload a picture in python 3
    7·1 answer
  • What is the top folder of the file tree called
    5·2 answers
  • The person who Oversee the direct work of employees and is responsible for the day-to-day tasks the employees complete is likely
    7·2 answers
  • Which storyboard component is a pictorial summary of how web pages in a website will connect with one another?
    12·1 answer
  • During a network evaluation an administrator discovers excessive cable between a transmitter and its antenna. To clean up the lo
    9·1 answer
  • How can you tell the difference between subnet addresses and interface addresses?
    13·1 answer
  • Get someone get her for me if need snap kell.c11
    10·1 answer
  • Why do we use if statements?
    9·1 answer
  • In the Burp Suite Program that ships with Kali Linux, what mode would you use to manually send a request (often repeating a capt
    14·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!