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 1 to Determine Miles-per-Gallon" endl;
cout "Enter 2 to Determine Distance" endl;
cout "Enter 3 to Determine Miles-per-Hour" endl;
cout "Enter 4 to Exit" endl;
cout "Enter your choice: ";
// Get user choice
cin >> choice;
switch (choice){
case 1: {
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.setMiles(mile);
car.setGallons(gallon);
// Display calculated MPG
cout "Miles per Gallon: " fixed setprecision(2) car.getMPG() endl;
break;
}
case 2: {
double speed, time;
Distance dist;
// Prompt user for input
cout "Enter Speed (miles/hour): ";
cin >> speed;
cout "Enter Time (hours): ";
cin >> time;
// Set values in Distance object
dist.setSpeed(speed);
dist.setTime(time);
// Display calculated distance
cout "Distance Traveled: " fixed setprecision(2) dist.getDistance()" miles" endl;
break;
}
case 3: {
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
spd.setDistance(distance);
spd.setTime(time);
// Display calculated speed
cout "Speed: " fixed setprecision(2) spd.getMPH()" miles per hour" endl;
break;
}
case 4: {
// Exit the program
cout "Exiting program. Goodbye!" endl;
break;
}
default:
// Display error message for invalid input
cout "Invalid choice. Please enter a number between 1 and 4." endl;
}
} while (choice !=4); // Repeat until user chooses to exit
return 0;
}
//Mileage.h
#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 setMiles(double mile){
miles = mile;
}
// Set the value of gallons
void setGallons(double 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;
}
};
//Distance.h
#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 setSpeed(double s){
speed = s;
}
// Set the value of time
void setTime(double 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;
}
};
//Speed.h
#pragma once
class Speed
{
private:
double distance; // Distance traveled in miles
double time; // Time taken in hours
public:
// Set the value of distance
void setDistance(double d){
distance = d;
}
// Set the value of time
void setTime(double 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;
}
};
Why is this program not running ? ? int main ( )

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Programming Questions!