-1

So I'm using C for a few days and I didn't have this problem before but now I have a problem with C scanning different number than the one the user enter. I feel like it prints the location of the number but not the number itself. The number I get every time is 6422076 and if I print another number that I've scan from the user it just show the same number -4, 6422072 so I'm pretty sure It has to do with the location the computer storage the numbers.

I tried to print it with a few other ways and always get the same weird number.

void measures()
{
    int height;

printf("\nEnter your height:\n");
scanf("%d",&height);
while(height<140 || height>210){
    printf("Invalid input, try again: \n");
    scanf("%d",&height);
}

printf("height: %d\n",&height);
}

not getting any errors

Asaf
  • 7
  • 1
  • 2
    Please see https://stackoverflow.com/questions/57842756/why-should-i-always-enable-compiler-warnings. You should always enable warnings when compiling your code. – S.S. Anne Oct 12 '19 at 15:26

1 Answers1

2

Here's your problem:

printf("height: %d\n",&height);

You're not printing the value of height. You're printing its address. Remove the address-of operator:

printf("height: %d\n",height);
dbush
  • 205,898
  • 23
  • 218
  • 273