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