Head scratcher

I have no hair left please help.

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
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
#include <iostream>
#include <string>
using namespace std;

int exit();

class Car
{
	private:
		int Year;
		string Make;
		int Speed;

	public:
		Car(int, string, int);
		int getYear();
		string getMake();
		int getSpeed();
		int Accelerate();
		void getDisplay();
		int Brake();
};

Car::Car(int Yr = 0, string Mk = " ", int Spd = 0)
{
	Year = Yr;.
	Make = Mk;
	Speed = Spd;
}

int Car::getYear()
{
	cout << "Enter the year of the car: ";
	cin >> Year;

	return Year;
}

string Car::getMake()
{
	cout << "Enter the make and model of the car: ";
	cin >> Make;

	return Make;
}

int Car::getSpeed()
{
	cout << "Enter the speed of the car: ";
	cin >> Speed;

	return Speed;
}

int Car::Accelerate()
{
	Speed = Speed + 5;

	return Speed;
}

int Car::Brake()
{
	Speed = Speed - 5;

	return Speed;
}

void Car::getDisplay()
{
	int choice;
	
	cout << "The car is a " << getYear() << " " << getMake() << " going " << getSpeed() << " MPH." << endl;
	Car car(getYear(), getMake(), getSpeed());

	do
	{
		cout << "          Menu         " << endl;
		cout << "-----------------------" << endl;
		cout << " 1. Accelerate         " << endl;
		cout << " 2. Brake              " << endl;
		cout << " 3. Exit               " << endl;
		cout << "-----------------------" << endl;
		cout << "\nEnter your choice:   " << endl;
		cin >> choice;

		switch (choice)
		{
			case 1: cout << "Accelerating";
					cout << car.Accelerate();
					break;
			case 2: cout << "Braking";
					cout << car.Brake();
					break;
			case 3: cout << "Exiting Program";
					exit();
					break;
		}

		while (choice < 1 || choice > 3)
		{
			cout << "\nYour choice must be 1-3. Re-enter.\n" << endl;
			cout << "          Menu         " << endl;
			cout << "-----------------------" << endl;
			cout << " 1. Accelerate         " << endl;
			cout << " 2. Brake              " << endl;
			cout << " 3. Exit               " << endl;
			cout << "-----------------------" << endl;
			cout << "\nEnter your choice:   " << endl;
			cin >> choice;
		}
	} while (choice != 3);
}

int exit()
{
	return (0);
}

int main()
{
	getDisplay();

	cout << endl << "Press ENTER to exit...";
	cin.clear();
	cin.sync();
	cin.get();

	return 0;
}
Last edited on
What exactly is wrong with it? What is it doing that is should't be? What is it NOT doing that it SHOULD be?

We need some sort of description of what you want your code to do.
For example, if the code does not compile, then you should tell the exact compiler error(s). (In the long run you should learn to read them yourself too.)
getDisplay() is a member function of class Car. It needs to be called on an object of type Car (which you haven't actually created yet).
Last edited on
Topic archived. No new replies allowed.