Question: Why is this program not running ? ? int main ( ) { int choice; do { / / Display menu options cout Enter 1
Why is this program not running
int main
int choice;
do
Display menu options
cout "Enter to Determine MilesperGallon" endl;
cout "Enter to Determine Distance" endl;
cout "Enter to Determine MilesperHour" endl;
cout "Enter to Exit" endl;
cout "Enter your choice: ;
Get user choice
cin choice;
switch choice
case :
double mile, gallon;
Mileage car;
Prompt user for input
cout "Enter Number of Miles: ;
cin mile;
cout "Enter Number of Gallons: ;
cin gallon;
Set values in Mileage object
car.setMilesmile;
car.setGallonsgallon;
Display calculated MPG
cout "Miles per Gallon: fixed setprecision car.getMPG endl;
break;
case :
double speed, time;
Distance dist;
Prompt user for input
cout "Enter Speed mileshour: ;
cin speed;
cout "Enter Time hours: ;
cin time;
Set values in Distance object
dist.setSpeedspeed;
dist.setTimetime;
Display calculated distance
cout "Distance Traveled: fixed setprecision dist.getDistance miles" endl;
break;
case :
double distance, time;
Speed spd;
Prompt user for input
cout "Enter Distance miles: ;
cin distance;
cout "Enter Time hours: ;
cin time;
Set values in Speed object
spdsetDistancedistance;
spdsetTimetime;
Display calculated speed
cout "Speed: fixed setprecision spdgetMPH miles per hour" endl;
break;
case :
Exit the program
cout "Exiting program. Goodbye!" endl;
break;
default:
Display error message for invalid input
cout "Invalid choice. Please enter a number between and endl;
while choice ; Repeat until user chooses to exit
return ;
Mileageh
#include
#include
using namespace std;
#pragma once
class Mileage
private:
double miles; Distance traveled
double gallons; Gallons of gas used
public:
Set the value of miles
void setMilesdouble mile
miles mile;
Set the value of gallons
void setGallonsdouble gallon
gallons gallon;
Get the value of miles
double getMiles
return miles;
Get the value of gallons
double getGallons
return gallons;
Calculate and return the miles per gallon
double getMPG
return miles gallons;
;
Distanceh
#pragma once
class Distance
private:
double speed; Speed in miles per hour
double time; Time taken in hours
public:
Set the value of speed
void setSpeeddouble s
speed s;
Set the value of time
void setTimedouble t
time t;
Get the value of speed
double getSpeed
return speed;
Get the value of time
double getTime
return time;
Calculate and return the total distance traveled
double getDistance
return speed time;
;
Speedh
#pragma once
class Speed
private:
double distance; Distance traveled in miles
double time; Time taken in hours
public:
Set the value of distance
void setDistancedouble d
distance d;
Set the value of time
void setTimedouble t
time t;
Get the value of distance
double getDistance
return distance;
Get the value of time
double getTime
return time;
Calculate and return the speed in miles per hour
double getMPH
return distance time;
;
Step by Step Solution
There are 3 Steps involved in it
1 Expert Approved Answer
Step: 1 Unlock
Question Has Been Solved by an Expert!
Get step-by-step solutions from verified subject matter experts
Step: 2 Unlock
Step: 3 Unlock
