Thread: Always returns FAIL, why???

  1. #1
    Registered User
    Join Date
    Feb 2003

    Always returns FAIL, why???

    #include <stdio.h>

    int main()

    int course_code, student_grade;

    printf("Please enter a valid number 1 -3\n");
    scanf("%d", &course_code);

    switch (course_code)
    case 1 : printf("ENGINEERING\n"); break;
    case 2 : printf("COMPUTER SCIENCE\n"); break;
    case 3 : printf("SCIENCE\n"); break;
    default : printf("INVALID COURSE CODE\n"); break;

    printf("Please enter a valid grade A,B,C\n");


    scanf("%s", &student_grade);

    switch (student_grade)
    case 'A' rintf("DISTINCTION"); break;
    case 'B' rintf("MERIT"); break;
    case 'C' rintf("PASS"); break;
    default rintf("FAIL"); break;


  2. #2
    Confused Magos's Avatar
    Join Date
    Sep 2001

    Give a man a fish and you feed him for a day.
    Teach a man to fish and you feed him for a lifetime.

  3. #3
    It's full of stars adrianxw's Avatar
    Join Date
    Aug 2001
    As an aside, when posting code it is a good idea to turn smilies off, and of course, use code tags.
    Wave upon wave of demented avengers march cheerfully out of obscurity unto the dream.

  4. #4
    Join Date
    Nov 2002
    Make student_grade a character type variable. You were using an int and then checking 'A' etc.
    char student_grade;
    Also %s is for strings so use this
    scanf(" %c", &student_grade);

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Non-blocking socket connection problem
    By cbalu in forum Linux Programming
    Replies: 25
    Last Post: 06-03-2009, 02:15 AM
  2. Lame null append cause buffer to crash
    By cmoo in forum C Programming
    Replies: 8
    Last Post: 12-29-2008, 03:27 AM
  3. Polynomials and ADT's
    By Emeighty in forum C++ Programming
    Replies: 20
    Last Post: 08-19-2008, 08:32 AM
  4. Replies: 2
    Last Post: 04-12-2004, 01:37 AM
  5. Contest Results - May 27, 2002
    By ygfperson in forum A Brief History of
    Replies: 18
    Last Post: 06-18-2002, 01:27 PM