#include <iostream>
#include <string>
usingnamespace std;
int exit();
class car
{
private:
int year;
string make;
string model;
int speed;
public:
car(int, string, string, int);
int getYear();
string getMake();
string getModel();
void getDisplay();
};
car::car(int yr = 0, string mk = " ", string mdl = " ", int spd = 0)
{
year = yr;
make = mk;
model = mdl;
speed = spd;
}
int car::getYear()
{
cout << "What is the year of the car you would like to drive today Michael?\n";
cin >> year;
return year;
}
string car::getMake()
{
cout << "And what car company makes the car Michael?\n";
cin >> make;
return make;
}
string car::getModel()
{
cout << "And what model is the car Michael?\n";
cin >> model;
return model;
}
void car::getDisplay()
{
int choice;
cout << "The car is a " << year << " " << make << " " << model;
cout << "\nLet's see how fast we can go Michael.\n ";
do
{
cout << "What would you like to do Michael?\n";
cout << " 1. Accelerate " << endl;
cout << " 2. Brake " << endl;
cout << "\n\nEnter your choice: " << endl;
cin >> choice;
switch (choice)
{
case 1: cout << "Accelerating...";
speed = speed + 5;
break;
case 2: cout << "Braking...";
speed = speed - 5;
if (speed >= 0)
cout << "You have stopped Michael.";
exit();
while (choice < 1 || choice > 3)
{
cout << "\nInvalid choice Michael...\n" << endl;
cin >> choice;
}
}
while (choice!=3)
{
exit();
}
}
}
int main()
{
car carObject;
carObject.getYear();
carObject.getMake();
carObject.getModel();
carObject.getDisplay();
cout << endl << "Press ENTER to exit...";
cin.clear();
cin.sync();
cin.get();
return 0;
}
I'm just not seeing the problem. I have to have the user input his car year, make and model and then accelerate and decelerate but I keep getting an error message that keeps popping up saying I have to define main()...I'm so lost right now.
Line 83: Where does your switch statement end? I don't see a } for it.
Line 63: I see a do, but I don't see the matching while statement. The while statements at lines 86 and 93 appear to stand on their own, although there is no reason that 93 should even be a loop.