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
  •  | 
  •  

Pergunta

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;
}
Foi útil?

Solução

You forgot to put your variable into the scanf:

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

Outras dicas

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

Like so:

scanf(" %d",&d);
Licenciado em: CC-BY-SA com atribuição
Não afiliado a StackOverflow
scroll top