Strange crash, good ol scanf

Write your question here.
So I am writing a program to help improve my C/C++ skills. It is loosely based on D&D rules and I am working on the fighting system. This is to be a very simple text based game and I will expand upon it later. For now I am just looking to start slowly and grow the code into something more robust. What I have is a very odd problem, I do not get a compile error but when I try to run the program it crashes. This is the section that I think my problems lies, it is a very simple if else, else if section but it will not go beyond the first printf without crashing. Please help
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
  //How to Hit
int Action;
int HitRoll;

  printf("A week monster attacks you press 1 to attack! Press 2 to Run!");
  scanf("%d\n", Action);
  if (Action == 1)
  {
             HitRoll =  MonAC1 - AttackRoll; 
             if (HitRoll > 0)
             {
                         printf("You struck the Monster! %d\n", HitRoll);
                         }
                         else
                         {
                             printf("You missed the Monster! %d\n", HitRoll);
                             }
  }
  else if (Action == 2)
  {
      printf("You Ran! COWARD!");
      }

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
scanf("%d", &Action);  /*no need for '\n' in scanf and when using ints, have '&' in front of the name*/

switch(Action)
{
        case 1:
       //actions
       break;

       case 2:
       //actions
       break;

      default:
      printf("invalid input\n");
      break;
}


try working with this setup. It may fix your problem.
Thank you very much it works very well, now to expand!
Topic archived. No new replies allowed.