Illegal use of pointer function

I'm attempting to do a simple output where the int variable "creaturelevel" is shown to the user, but it's giving back an error that says: "oroperator.cpp": E2087 Illegal use of pointer in function main() at line 18

It's a variable; I never declared a pointer in this project. I've looked but I don't understand what the problem is, can you help me figure it out?

full code:

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
#include <iostream>

using namespace std;

int main()
{
  /* deciding whether or not to attack player if any value is
  true */
  int playerlevel;
  int creaturelevel;
  bool playerisattacking;
  int attackordefend;
  cout<<"Your level is: ";
  cin>>playerlevel;
  creaturelevel = playerlevel - 12;
  cout<"Creeping along a dark hallway with your M4 Carbine \
  ready to fire...the floors are soaked with blood from last \
  nights ambush. A creature approaches, level " << creaturelevel << "\n";
  cout<<" . Do you want to attack it \
  or sneak past it?\n";
  cout<<"Attack: 1\nDefend: 2\n";
  //if attacks, game checks for player level versus creature
  //level.
  switch (attackordefend) // checks whether or not hes attacking
  {
    case 1:
          bool playerisattacking = true; // player is attacking
         if ( (playerisattacking == false) || (playerlevel < creaturelevel + 5) )
        {
          cout<<"The creature spots your effortless attack and you are ambushed...\nWith\
          a broken leg and a cracked rib, you limp out of the building\n but bleed to death\
          before you can reach your teammates.\n\n\n\t\t\t\t\t\tGame over.\n";
          cin.get();
        }
      case 2:
          cout<<"You successfully defend against the creature, and kill it with a \
          headshot.\n";
  }
  cin.get();
}


another error I received for reference: "oroperator.cpp": E2126 Case bypasses initialization of a local variable in function main() at line 35

Thanks.

P.S.: the point of the program itself is to test out the OR logical operator when it comes to if statements.
Last edited on
Line 16: You're doing cout < instead of cout <<.
Line 27: Don't declare variables inside switch cases. If you need more variables, do it like this:
1
2
3
4
5
6
7
8
9
10
11
12
13
switch (something){
    case 0:
        {
            int a;
        }
        break;
    case 1:
        {
            int a,
                b;
        }
        break;
}

Variables declared like that only have scope inside those blocks.
Last edited on
Topic archived. No new replies allowed.