dmitrikonnikov
dmitrikonnikov

Reputation: 53

Getting error saying that my program has crashed in C even though it show no issue with the syntax

I am confused as to why my program keeps on crashing. I am using Code Blocks, an open source IDE.

Here is the code:

int main()
{
  int age;
  char gender;

  printf("What is your age?\n");
  scanf(" %d", age);

  printf("What is your gender? \(m/f)\n");
  scanf(" %c", gender);

  if (age>=18){
    printf("Access granted! Please proceed\n");

    if (gender == 'm'){
      printf("What's up dude?");
    };
    if (gender == 'f'){
        printf("How's it going dudette?");
    };
  };
  if (age<18){
    printf("Access denied. Please get on with your life.\n");
  };

  return 0;
}

Upvotes: 1

Views: 47

Answers (1)

bruceg
bruceg

Reputation: 2513

scanf requires a pointer to the variable you're setting. So, you need to do:

scanf(" %d", &age);

and similar for gender

Upvotes: 2

Related Questions