Thread: problem with the computers replie to the input

  1. #1
    Registered User
    Join Date
    Apr 2008
    Posts
    7

    problem with the computers replie to the input

    Alright now my objective is a little corny, but im trying to make a program to identify a person by age or name. (also it was to get me to start coding, I'm making to put in it as I go.) I already can get it by inputting a number, but when i try to get it to replie to names it doesn't work. i think the problem is with the scanf but i honestly don't know. please help

    Code:
    #include <stdio.h>
    int main(void)
    {
     int x;
        x = 1;
      {
     int age;
     char name;
     
     do{
        printf("Hello, I am the Smart computer.\nTell me your name or age, and I will Identify:");
     scanf("%d", &age);
     scanf("%d", &name);
         
        if(age == 14) {
            system("cls");
      printf("How's it hangin Ben\n", x);
      system("pause");
      system ("cls");
     }
        else if ( age == 42) {
             system("cls");
      printf("Hey pops\n", x);
      system("pause");
      system ("cls");
      }
     else if ( age == 17) {
             system("cls");
      printf("hey good lookin\n", x);
      system("pause");
      system ("cls");
     }
     else if ( age == 9) {
             system("cls");
          printf("Nick, two for flinching!!!!\n", x);
             system("pause");
             system ("cls");
             }
        else if (age == 6) {
             system("cls");         
             printf("Hey, Mikal! :P\n", x);
             system("pause");
             system ("cls");
             }
        else if (age == 4) {
             system("cls");         
             printf("Chewy, I'm ganna eat'ya!!\n", x);
             system("pause");
             system ("cls");
             }
        else if (age == 2) {
             system("cls");         
             printf("Hey roo, wannta play some hockey aye?\n", x);
             system("pause");
             system ("cls");
             }    
        else if (age == 21) {
             system("cls");         
             printf("Kansas won.. it seems the student has become the master.\n", x);
             system("pause");
             system ("cls");
             }
        else if (age == 23) {
             system("cls");         
             printf("Ryan Andrew... bluesclues, bluesclues.\n", x);
             system("pause");
             system ("cls");
             }
        else if (age == 43){
             system("cls");         
             printf("Congragulations on the new baby, God Bless.\n", x);
             system("pause");
             system ("cls");
             }
        else if (name == 'cameron'){
             system ("cls");
             printf ("Oh! How's it goin boss?\n");
             system ("pause");
             system ("cls");
             }
        else if (name == 'exit'){
             system("cls");      
             printf("Sysetm failer, thanks alot.\n", x);
             system("pause");
             getchar();
             return 0;
             }
             else {
             system("cls");
             printf("I don't know you, therefore you don't exsist. Good day.\n", x);
             }
    }while (x != 0);
    }         
             system("pause");
    }

  2. #2
    and the Hat of Guessing tabstop's Avatar
    Join Date
    Nov 2007
    Posts
    14,336
    char name; means that name can only hold one letter. You can't read in a char with %d either. Look up how to use character arrays.

  3. #3
    Registered User
    Join Date
    Apr 2008
    Posts
    7
    ill do that right now, thank you

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. geting input in C, problem in getting input
    By BujarM in forum C Programming
    Replies: 3
    Last Post: 04-17-2009, 09:38 PM
  2. A question related to strcmp
    By meili100 in forum C++ Programming
    Replies: 6
    Last Post: 07-07-2007, 02:51 PM
  3. Input statement problem
    By une in forum C Programming
    Replies: 3
    Last Post: 05-29-2007, 11:16 PM
  4. Stuck on Input problem
    By Syneris in forum C++ Programming
    Replies: 4
    Last Post: 01-23-2006, 10:53 PM
  5. Problem with text input
    By newbie in forum C++ Programming
    Replies: 2
    Last Post: 03-10-2002, 04:44 PM