Quickie Q :o) (yea!!)

This is a discussion on Quickie Q :o) (yea!!) within the C Programming forums, part of the General Programming Boards category; i got this program to work (yea!!!!!!), but i have 1 error... for some reason the last else clause is ...

  1. #1
    Registered User
    Join Date
    Jul 2002
    Posts
    48

    Quickie Q :o) (yea!!)

    i got this program to work (yea!!!!!!), but i have 1 error... for some reason the last else clause is an 'illegal else with an if'... i looked at the book a bajillion times and i'm doing exactly what the model says in the book...
    here's my code:

    /* SEC5.3 EX 14 */
    /* DATE: 07-23-02 */

    #include <stdio.h>

    int main()
    {
    int grade, one, two;

    printf("Enter numerical grade: ");
    scanf("%d", &grade);

    if ( grade == 100 )
    printf("Letter Grade: A\n");
    else if ( 0<=grade && grade>=99 )
    two = grade % 10;
    one = grade / 10;
    else
    printf("ERROR\n");


    printf("Letter Grade: ");
    switch (one) {
    case 0: case 1: case 2: case 3: case 4: case 5:
    printf("F\n"); break;
    case 6: printf("D\n");
    break;
    case 7: printf("C\n");
    break;
    case 8: printf("B\n");
    break;
    case 9: printf("A\n");
    break;
    }

    return 0;
    }

  2. #2
    Mayor of Awesometown Govtcheez's Avatar
    Join Date
    Aug 2001
    Location
    MI
    Posts
    8,825
    if ( 0<=grade && grade>=99 )
    two = grade % 10;
    one = grade / 10;
    else


    If your if statement has more than one line, you need to use braces

    if ( 0<=grade && grade>=99 )
    {
    two = grade % 10;
    one = grade / 10;
    }
    else

  3. #3
    Registered User
    Join Date
    Jul 2002
    Posts
    48
    thanx Govtcheez~!!! the braces did the trick )

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Quickie Linked List Deallocation question.
    By Kurisu in forum C# Programming
    Replies: 4
    Last Post: 06-09-2006, 07:23 AM
  2. Quickie on Arrays...
    By twomers in forum C++ Programming
    Replies: 4
    Last Post: 12-14-2005, 11:13 AM
  3. quickie question
    By kimimaro in forum C Programming
    Replies: 1
    Last Post: 03-21-2005, 10:38 AM
  4. A quickie about fstream.h
    By Unregistered in forum C++ Programming
    Replies: 6
    Last Post: 10-02-2001, 07:10 PM

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