Problem with entering data for variable

Hi, I'm having trouble entering data for a variable. What I'm trying to do is to make what the user enters, the data inside that variable.

Link to the code:

http://pastebin.com/KMXKC4w2

It's near the bottom, in line 143. The logic should be the following:

If (Input[0] == 1){
AllCars.FuelType = "Petrol"
}
else if (Input[0] == 2){
AllCars.FuelType = "Diesel"
}

however, it won't let me do that.

Before anyone says anything about the way I am doing this, I do not want to change it, I only want to know that one thing... how to make that ^^ above work and yes, I am aware I use system("PAUSE") and system("clr").
closed account (o3hC5Di1)
Hi there,

I think the problem is because Input is declared as a char, and your comparing it to an integer.

In order to solve this, simply do if (Input[0] == '1')

Hope that helps.

All the best,
NwN
Hi,

Thanks for the reply - I don't know why I didn't see that in the first place, however, I'm still getting an error from line 143. The error i'm getting reads:

char AllCars::FuelType[6]
Error: a nonstatic member reference must be relative to a specific object


Any ideas?
I was looking over your code and have a question.

It seems to me that Vans, SportsCars and FourByFour should inherit from AllCars but they don't, is this correct?

If so...

Class declarations should look like...

Class SportsCars : public AllCars...

Your error on line 143 is occuring because AllCars is a class not an instance of a class. You must first instantiate an AllCars object before modifying said value.
Hi,

I have changed the code slightly, but still am having the same trouble. I can't seem to make a variable contain a specific piece of data.

Here is the updated version of the code:

http://pastebin.com/XXstAn9f

I am running out of ideas... and time.

Any help is greatly appreciated.

TheEagle
closed account (o3hC5Di1)
Hi there,

You still haven't declared your child classes as actual children of AllCars:

1
2
3
4
5
6
class SportsCars}
class SportsCars: public AllCars {
      public:
             bool SoftTop;
             bool Alloys;
             };


Also, to clarify Georgewashere's point, if you want to call a method or property of an AlCars object, you need to do to as such:

1
2
AllCars AllCarObject;
AllCarObject.method();


A class is a blueprint (like that of a house), the actual house is called an object, and only in an object (actual house as opposed to the mere plan)you can actually do stuff like house.turnOnHeating(); .

Hope that helps.

all the best,
NwN
Topic archived. No new replies allowed.