Always returns FAIL, why???

This is a discussion on Always returns FAIL, why??? within the C Programming forums, part of the General Programming Boards category; #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) { ...

  1. #1
    Registered User
    Join Date
    Feb 2003
    Posts
    12

    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");

    /*gets(student_grade);*/

    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
    Location
    Sweden
    Posts
    3,145
    What?
    MagosX.com

    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
    Posts
    4,831
    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
    Posts
    303
    Make student_grade a character type variable. You were using an int and then checking 'A' etc.
    Code:
    char student_grade;
    Also %s is for strings so use this
    Code:
    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, 02: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 Cprogramming.com
    Replies: 18
    Last Post: 06-18-2002, 01:27 PM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21