-5

I am trying to learn how to write in C. I am new to the whole thing. Got stuck on code. Just trying to find out how to make this code in to a pop up box to ask a question and then do something with the answer.

I'll put the code in now:

#include <stdio.h>
#include <stdlib.h>

int main ()
{
    int age;
    printf ("whats yo age???"/*condition goes here */);
        scanf ("%d", age);
}

{    if (age <30)
        /*condition goes here */
        printf ("you a young buck");
        /*if condition is non-zero (true), this code will execute*/
}


{
   scanf
  if ( age==30);
    /*condition goes here*/
    printf ("you getting old");
    /*if condition is non-zero (true), this code will execute*/
}//
halfer
  • 19,824
  • 17
  • 99
  • 186
  • 4
    "id appreciate any help" --> `int age; ... scanf ("%d", age);` implies code is not compiled with warnings fully enabled. Save time, lots of time and enable all warnings. You get faster feedback than posting on SO. – chux - Reinstate Monica Mar 28 '20 at 20:21
  • You should start with [a good book](https://stackoverflow.com/questions/562303/the-definitive-c-book-guide-and-list) to learn the language fundamentals. – Blastfurnace Mar 28 '20 at 20:43

1 Answers1

0

There are multiple problems in your code:

First of all you should put it in the main function block. (at least until you understand how functions work). Then when you use scanf, most of the time you have to add & sign, which indicates you will place the value in variable which is located at this address. (variable age in your case)

The code should look something like this:

#include <stdio.h>
#include <stdlib.h>

int main ()
{
    int age;
    printf ("whats yo age???");
    scanf ("%d", &age);

    if (age < 30) {
        printf ("you a young buck");
    }
    else if (age == 30) {
      printf ("you getting old");
   }
}
V. Sambor
  • 12,361
  • 6
  • 46
  • 65