Elevator program errors

Don't know what I'm doing wrong. Trying to write an elevator program that allows the user to display floor and move it up and down.

Getting these errors
'::main' must return 'int'
void main()\

expected initializer before 'cout'
"\n initialize data for l1";

error: 'l1' was not declared in this scope
l1.initdata();

error: expected ';' before 'cin'
cin >> choice;

expected ';' before '}' token
}

Thank you!







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
  #include <iostream>
using namespace std
class elevator
{
private:
    int elevatorfloor;
public:
    void displaydata()
        {
        cout << "Elevator Floor:"
        << elevatorfloor << endl;
        }
    void initdata()
    {
    cout << "Enter Floor number: " ;
    cin >> elevatorfloor;
    }
    void lowerelevator()
        {
            --elevatorfloor;
        }
     void liftelevator()
        {
            ++elevatorfloor;
        }
};
    void main()
{
char choice = 'x';

elevator l1

cout<< "\n initialize data for l1";
l1.initdata();

while (choice != 'q')
    {
        cout<< "\nEnter 1 to raise, 2 to lower or q to quit"
        cin >> choice;
        switch (choice)
            {
            case '1':
                cout<< "Raising elevator one floor";
                l1.Raiseelevator();
                break;
            case '2':
                cout<< "Lowering elevator one floor";
                l1.lowerelevator;
                break;
            }   
    }
cout<<"\nCurrent floor number:";
l1.displaydata();
return 0 
}
error: expected ';' before 'cin'
cin >> choice;

You need to put a ; after this line:

cout<< "\nEnter 1 to raise, 2 to lower or q to quit"; <---


edit: expected ';' before '}' token
}

token?
Last edited on
"void main()" is not valid C++, return type of main is "int", so:

1
2
3
int main()
{
}


missing ";" in lines 2, 31 and 38
You didn't declare or define Raiseelevator() - see line 44 - anywhere, perhaps you meant to use "liftelevator()" instead.
In line 48 you forgot to use parentheses "()" with your function call.
Still getting this:

In function 'int main()': 33:1: error: expected initializer before 'cout' 34:1: error: 'l1' was not declared in this scope 55:1: error: expected ';' before '}' token

Did I miss something?
#include <iostream>
using namespace std;
class elevator
{
private:
int elevatorfloor;
public:
void displaydata()
{
cout << "Elevator Floor:"
<< elevatorfloor << endl;
}
void initdata()
{
cout << "Enter Floor number: " ;
cin >> elevatorfloor;
}
void lowerelevator()
{
--elevatorfloor;
}
void liftelevator()
{
++elevatorfloor;
}
};
int main()
{
char choice = 'x';

elevator l1

cout<< "\n initialize data for l1";
l1.initdata();

while (choice != 'q')
{
cout<< "\nEnter 1 to raise, 2 to lower or q to quit";
cin >> choice;
switch (choice)
{
case '1':
cout<< "Raising elevator one floor";
l1.Raiseelevator();
break;
case '2':
cout<< "Lowering elevator one floor";
l1.lowerelevator();
break;
}
}
cout<<"\nCurrent floor number:";
l1.displaydata();
return 0
}


Thanks for replying, by the way.
Last edited on
Line 31: As previously mentioned, you need a ;

Line 44: Also as previously mentioned, you have no function name Raiseelevator().

Line 54: You need a ;

PLEASE USE CODE TAGS (the <> formatting button) when posting code.
http://v2.cplusplus.com/articles/jEywvCM9/
It makes it easier to read your code and it also makes it easier to respond to your post.
Hint: You can edit your previous post, highlight your code and press the <> formatting button.
Last edited on
Topic archived. No new replies allowed.