Thread: New Amateur with C needs help!

  1. #1
    Registered User
    Join Date
    Sep 2016
    Posts
    1

    Question New Amateur with C needs help!

    Hey guys!

    I just began to learn programming in c (sorry for my gramma)
    Right now I am trying out the if statement..

    Somehow the statement "you are a kid" does not show, when I enter the age below 20.

    Where is my mistake?? :S

    Code:
    #include <stdio.h>
    #include <stdlib.h>
    
    
    int main()
    {
      char firstname[20];
      char name[] = "Nick";
      char age[3];
      printf("Hello my name is %s. What is your name? \n" ,name);
    
    
      scanf("%s", firstname);
      printf("nice to meet you %s \n", firstname);
    
    
      printf("How old are you? \n");
      scanf("%d", age);
    
    
      if ( age <= 20){
        printf("You are a kid");
    
    
      }
    
    
        if  ( age > 20){
             printf("You are not a kid");
    
    
        }
        return 0;
        }

  2. #2
    Registered User
    Join Date
    Jul 2016
    Posts
    9
    You are trying to compare a string to an integer. You can either receive input as a string and convert it to an integer with functions like atoi() or you can directly receive input in integer form to fix this.

    Code:
    int age;
    scanf("%d",&age);

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Help please (amateur programmer)!!!
    By jimgeor in forum C Programming
    Replies: 1
    Last Post: 05-06-2012, 04:05 PM
  2. C++ and SDL amateur looking for a game project.
    By traitor_651 in forum Projects and Job Recruitment
    Replies: 0
    Last Post: 10-15-2010, 11:16 AM
  3. problem for amateur lol
    By clarky101 in forum C Programming
    Replies: 3
    Last Post: 10-21-2007, 09:04 AM
  4. Amateur question.
    By RP319 in forum C++ Programming
    Replies: 11
    Last Post: 02-07-2005, 07:27 AM
  5. very amateur question:
    By jemer in forum C++ Programming
    Replies: 5
    Last Post: 06-19-2003, 02:41 PM

Tags for this Thread