Thread: error if strcmp and getch show that undeclared

  1. #1
    Registered User
    Join Date
    Jul 2011
    Location
    Kuala Lumpur, Malaysia, Malaysia
    Posts
    5

    Cool error if strcmp and getch show that undeclared

    My error with line 20 if strcmp and line 75 getch show that undeclared,somebody
    can help me.TQ!

    Below is my error result:

    Code:
    #include <stdio.h>
    
    main ()
    {
        int credit_hour1,credit_hour2, totalcredithours;
        char fix_grade[3]="A";
        char grade1[3];
        char grade2[3];
        float calculation1, calculation2, totalcalculation,GPA;
    
        printf("Please enter your Grade for subject_1 :");
        scanf("%s",&grade1);
        printf("Please enter your credit hour for subject_1 :");
        scanf("%d",&credit_hour1);
        printf("Please enter your Grade for subject_2 :");
        scanf("%s",&grade2);
        printf("Please enter your credit hour for subject_2 :");
        scanf("%d",&credit_hour2);
    
        if(strcmp(grade1,"A" ) == 0)
        calculation1 = 4.00 * credit_hour1;
        if (strcmp(grade1, "A-")== 0)
        calculation1 = 3.67 * credit_hour1 ;
        if(strcmp(grade1,"B+" ) == 0)
        calculation1 = 3.33 * credit_hour1;
        if (strcmp(grade1, "B")== 0)
        calculation1 = 3.00 * credit_hour1;
        if(strcmp(grade1,"B-" )== 0)
        calculation1 = 2.67 * credit_hour1;
        if (strcmp(grade1, "C+")== 0)
        calculation1 = 2.33 * credit_hour1;
        if(strcmp(grade1,"C" ) == 0)
        calculation1 = 2.00 * credit_hour1;
        if (strcmp(grade1, "C-")== 0)
        calculation1 = 1.67 * credit_hour1;
        if(strcmp(grade1,"D+" ) == 0)
        calculation1 = 1.33 * credit_hour1;
        if (strcmp(grade1, "D")== 0)
        calculation1 = 1.00 * credit_hour1;
        if(strcmp(grade1,"F" ) == 0)
        calculation1 = 0.00 * credit_hour1;
        else
          if(strcmp(grade2,"A" ) == 0)
        calculation2 = 4.00 * credit_hour2;
        if (strcmp(grade2, "A-")== 0)
        calculation2 = 3.67 * credit_hour2 ;
        if(strcmp(grade2,"B+" ) == 0)
        calculation2 = 3.33 * credit_hour2;
        if (strcmp(grade2, "B")== 0)
        calculation2 = 3.00 * credit_hour2;
        if(strcmp(grade2,"B-" ) == 0)
        calculation2 = 2.67 * credit_hour2;
        if (strcmp(grade2, "C+")== 0)
        calculation2 = 2.33 * credit_hour2;
        if(strcmp(grade2,"C" ) == 0)
        calculation2 = 2.00 * credit_hour2;
        if (strcmp(grade2, "C-")== 0)
        calculation2 = 1.67 * credit_hour2;
        if(strcmp(grade2,"D+" ) == 0)
        calculation2 = 1.33 * credit_hour2;
        if (strcmp(grade2, "D")== 0)
        calculation2 = 1.00 * credit_hour2;
        if(strcmp(grade2,"F" ) == 0)
        calculation2 = 0.00 * credit_hour2;
        
    
    totalcredithours = credit_hour1 + credit_hour2  ;  
    totalcalculation = calculation1 + calculation2 ;
    GPA = totalcalculation / totalcredithours ;
    
     printf("%.2f\n",totalcalculation);  
     printf("%d\n", totalcredithours); 
     printf("GPA %.2f\n", GPA);
        
    getch();
    
    }

  2. #2
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    39,659
    strcmp is in string.h
    getch is in conio.h, you should read the FAQ for better ways of stopping the window disappearing when the program ends.
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.

  3. #3
    C++まいる!Cをこわせ!
    Join Date
    Oct 2007
    Location
    Inside my computer
    Posts
    24,654
    This is C. Perhaps you should use a C compiler and put it in the C section.
    Quote Originally Posted by Adak View Post
    io.h certainly IS included in some modern compilers. It is no longer part of the standard for C, but it is nevertheless, included in the very latest Pelles C versions.
    Quote Originally Posted by Salem View Post
    You mean it's included as a crutch to help ancient programmers limp along without them having to relearn too much.

    Outside of your DOS world, your header file is meaningless.

  4. #4
    Registered User
    Join Date
    Jul 2011
    Location
    Kuala Lumpur, Malaysia, Malaysia
    Posts
    5
    ok. i try it 1st. tq!

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. error: ‘numberOfElements’ undeclared
    By leahknowles in forum C Programming
    Replies: 6
    Last Post: 03-23-2011, 08:58 AM
  2. Undeclared identifier error
    By pobri19 in forum C Programming
    Replies: 2
    Last Post: 04-11-2010, 09:40 PM
  3. error: undeclared (need some help)
    By Nadril in forum C++ Programming
    Replies: 17
    Last Post: 02-22-2008, 12:59 PM
  4. undeclared indentifier error
    By SpEkTrE in forum C Programming
    Replies: 7
    Last Post: 11-18-2003, 07:08 PM
  5. Compiler error error C2065: '_beginthreadex; : undeclared identifier
    By Roaring_Tiger in forum Windows Programming
    Replies: 3
    Last Post: 04-29-2003, 01:54 AM