Am I using the constructor arguments incorrectly?

I am trying to display the model year, model, make, and speed and all this information comes up blank when I run the program. I tried switching some things around. Did I use the constructor wrong when I created the Car object called SuperSpeeder? I put arguments in when I created the object. What gives?

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
#include <iostream>
#include <string>
#include <iomanip>
#include "Car.h"
using namespace std;

int main ()
{
	int year, speed;
	string make, model;
	Car SuperSpeeder (2010, "Mitsubishi", "Lancer Evolution X");

	for (int x = 1; x <= 5; x++)
	{
		SuperSpeeder.Accelerate();
	}
	cout << "The current speed after acceleration: ";
	SuperSpeeder.getSpeed();
	cout << " MPH\n";

	for (int x = 1; x <= 5; x++)
	{
		SuperSpeeder.Brake();
	}

	cout << "The current speed after hitting the brakes: ";
	SuperSpeeder.getSpeed();
	cout << " MPH\n";

	cout << "\nCar Specifications" << endl;
	cout << "__________________" << endl;
	cout << "Make: ";
	SuperSpeeder.getMake();
	cout << "\nModel: ";
	SuperSpeeder.getModel();
	cout << "\nModel Year: ";
	SuperSpeeder.getYear();
	cout << endl;

	system("pause");
	return 0;

}


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
#ifndef CAR_H
#define CAR_H
#include <string>
using namespace std;

class Car 
{
private:
	int yearModel, speed;
	string make, model;

public:
	
	Car (int year, string CarMake, string CarModel)
	{
		yearModel = year;
		make = CarMake;
		model = CarModel;
		speed = 0;
	}

	int Accelerate ()
	{ return speed += 5;}

	int Brake ()
	{ return speed -= 5;}

	int getYear ()
	{ return yearModel;}

	int getSpeed ()
	{ return speed;}

	string getMake ()
	{ return make;}

	string getModel ()
	{ return model;}



};

#endif 
You aren't actually displaying the results.

These two lines, for instance.
1
2
cout << "The current speed after acceleration: ";
	SuperSpeeder.getSpeed();


You are printing the string "The current speed after acceleration: ".
Then, the next line, you are calling 'getSpeed()', the result of which is lost forever because you don't do anything with it.

It should be:

cout << "The current speed after acceleration: " << SuperSpeeder.getSpeed() << endl;

All the other instances fail for the same reason.
xismn,

That was exactly it.
Thank you!
Topic archived. No new replies allowed.