You're doing that inside The constructor's parameters. It's not exactly what you think it is. That constructor is made so that you will send in 3 values to it, and it will give those values to your private variables.
Car::Car(double YearModel, string Make, double Speed = 0)
This constructor takes 3 values as you can see for yourself. Your problem is that you're only sending in to 2 out of 3
Car myCar(YearModel, Make);
you're missing the speed part.
I believe you need to ask the user for the speed. And then send it in so it looks like this
Car myCar(YearModel, Make, speed);
And inside the constructor initialize your private variables.
1 2 3 4 5 6 7
|
Car::Car(double userYearModel, string userMake, double userSpeed)
{
Speed = userSpeed;
YearModel = userYearModel;
Make = userMake;
}
|
Now, all the values the user entered for the model, make and speed, is stores in the variables you created for your class
1 2 3 4 5 6
|
class Car
{
private:
double YearModel;
string Make;
double Speed;
|
edit: I changed the name of the variables inside the constructor parameter so you can see things more clearly, it can be confusing when they have the same name.