Classes

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
  #include <iostream>
#include <string>
using namespace 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.
Which line is the error on?
line 98. I added and subtracted a few "}" before main because i didnt know if i had enough/ too much but i keep getting it
I don't know what's your problem.
But if you use tab correctly, there'll be not much hard to notice that?

And } in line 97, it from do{}.
So where's while(); after do{}?
Like lsk said, if i change line 97 to
 
	} while (1);


then the compiler stops moaning.
Sort out your indentation, it's making your code very difficult to read. Also stuff like this
1
2
3
			if (speed >= 0)
				cout << "You have stopped Michael.";
			exit();

Do you want exit() to be called when if evaluates to true? Because at the moment that exit() will be called everytime you go into case 2.
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.

Topic archived. No new replies allowed.