What did I do wrong? Trying to get user to enter numeric values for different variables

StackOverflow https://stackoverflow.com/questions/21421824

  •  04-10-2022
  •  | 
  •  

문제

I am trying to figure out how I can make my program read what the user is typing in, such as a numeric value in this case but I'm having trouble. Here is what I put so far. The first part of the code is just a fake name and email address that just outputs my credentials (so that shouldn't matter).

#include <stdio.h>

int main(void)

{
     printf("John Smith\n");
     printf("abc@abc.com\n");

     /* User must enter values in feet */
     int d;
     printf("Enter length for side a: \n");
     scanf(" %d");

     return 0;
}
도움이 되었습니까?

해결책

You forgot to put your variable into the scanf:

scanf(" %d", &d);
printf("You entered %d\n", d);

다른 팁

To read a value from scanf you must give it the address of the variable using (&)

Like so:

scanf(" %d",&d);
라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top