c++ program compiler error?

I am getting this one error for my program that says "fatal error C1075: end of file found before the left brace."

Can anyone help me fix this error?

Here is my code in case you want to try running it on your own compiler.

#include <iostream>
using namespace std;
class Vehicle {
private:
int Age; //The age of the vehicle

protected:
float Price; //The price of the vehicle

public:
Vehicle(){Age = 0; Price = 0.0; }; //default constructor sets age=0, and price=0.0
~Vehicle(){Age = 0; Price = 0.0; }; //destructor sets age=0, and price=0.0
void setAge(int x){Age=x;}; //Takes an integer parameter, returns nothing
void setPrice(float x){Price=x;}; //Takes a float parameter, returns nothing
int getAge(){return Age;};// Takes no parameters, returns the vehicle’s age
float getPrice(){return Price;}; // Takes no parameters, returns the vehicle’s price
};
class Car: public Vehicle
{
private:
bool RaceCarStatus;
public:
Car(){RaceCarStatus = false;};
~Car(){RaceCarStatus = false;};
void setRaceCarStatus(bool y){RaceCarStatus=y;};
bool getRaceCarStatus(){return{RaceCarStatus;};
};
int main()
{
Vehicle x;
cout << "Initial value for x: " << endl;
cout << "Age = " << x.getAge() << " Price= " << x.getPrice() << endl;
x.setAge(40);
x.setPrice(20000);
cout << "Modified value for x: " << endl;
cout << "Age = " << x.getAge() << " Price= " << x.getPrice() << endl;

Car y;
cout << "Initial value for x: " << endl;
cout << "Age = " << x.getAge() << " Price= " << x.getPrice() << "Race Car Status="<< y.getAge()<< endl;
x.setAge(40);
x.setPrice(20000);
y.setRaceCarStatus(true);
cout << "Modified value for x: " << endl;
cout << "Age = " << x.getAge() << " Price= " << x.getPrice() << "Race Car Status="<< y.getAge() <<endl;
return 0;
}
Not to sound lazy, but comparing my edited source to yours should show you all the mistakes. Basically you had a lot of unnecessary semi-colons:


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
#include <iostream>
using namespace std;
class Vehicle
{
private:
    int Age; //The age of the vehicle

protected:
    float Price; //The price of the vehicle

public:
    Vehicle()
    {
        Age = 0;
        Price = 0.0;
    } //default constructor sets age=0, and price=0.0
    ~Vehicle()
    {
        Age = 0;
        Price = 0.0;
    } //destructor sets age=0, and price=0.0
    void setAge(int x)
    {
        Age=x;
    } //Takes an integer parameter, returns nothing
    void setPrice(float x)
    {
        Price=x;
    } //Takes a float parameter, returns nothing
    int getAge()
    {
        return Age;
    }// Takes no parameters, returns the vehicle’s age
    float getPrice()
    {
        return Price;
    } // Takes no parameters, returns the vehicle’s price
};
class Car: public Vehicle
{
private:
    bool RaceCarStatus;
public:
    Car()
    {
        RaceCarStatus = false;
    }
    ~Car()
    {
        RaceCarStatus = false;
    }
    void setRaceCarStatus(bool y)
    {
        RaceCarStatus=y;
    };
    bool getRaceCarStatus()
    {
        return RaceCarStatus;
    }
};
    int main()
    {
        Vehicle x;
        cout << "Initial value for x: " << endl;
        cout << "Age = " << x.getAge() << " Price= " << x.getPrice() << endl;
        x.setAge(40);
        x.setPrice(20000);
        cout << "Modified value for x: " << endl;
        cout << "Age = " << x.getAge() << " Price= " << x.getPrice() << endl;

        Car y;
        cout << "Initial value for x: " << endl;
        cout << "Age = " << x.getAge() << " Price= " << x.getPrice() << "Race Car Status="<< y.getAge()<< endl;
        x.setAge(40);
        x.setPrice(20000);
        y.setRaceCarStatus(true);
        cout << "Modified value for x: " << endl;
        cout << "Age = " << x.getAge() << " Price= " << x.getPrice() << "Race Car Status="<< y.getAge() <<endl;
        return 0;
    }


You don't need semi-colons at the ending brace of a function but you do need one at the ending brace of a class. You also has some weird bracketing syntax:

bool getRaceCarStatus(){return{RaceCarStatus;};

should be:

bool getRaceCarStatus(){return RaceCarStatus;}

Syntax errors are really all that was wrong with your code.
Last edited on
Topic archived. No new replies allowed.