Simple Case is messed

This is a discussion on Simple Case is messed within the C Programming forums, part of the General Programming Boards category; Hi, I had this working before but now it doesn't seem to work. Whenever I type the number in it ...

  1. #1
    Unregistered
    Guest

    Simple Case is messed

    Hi,

    I had this working before but now it doesn't seem to work. Whenever I type the number in it goes to the error message. It should print the message for each number.

    Please help.

    #include <stdio.h>

    int barnum;

    void main()

    {

    printf(“What is the reading on your barometer?”);
    scanf(“%d”, barnum);

    switch(number)

    { //START of case

    case 1:
    printf(“STORM: Wear something suitable for a storm!\n\n”);
    break;

    case 2:
    printf(“RAIN: Wear a raincoat!\n\n”);
    break;

    case 3:

    printf(“CHANGE: Wear a jacket and take an umbrella!\n\n”);
    break;

    case 4:
    printf(“FAIR: Wear a jacket just in case!\n\n”);
    break;

    case 5:
    printf(“DRY: You’ll be ok! Wear hardly any clothes at all!\n\n”);
    break;

    default:
    printf(“You entered an invalid number you idiot!”);

    } //END of case

    }

  2. #2
    Registered User
    Join Date
    Mar 2002
    Posts
    88
    switch(number)

    must be

    switch(barnum)

  3. #3
    Unregistered
    Guest
    your scanf should also read:

    scanf("%d", &barnum);

  4. #4
    Code Goddess Prelude's Avatar
    Join Date
    Sep 2001
    Posts
    9,796
    And don't use void main, use
    int main ( void )

    -Prelude
    My best code is written with the delete key.

  5. #5
    skumar
    Guest
    all the above and also u shud b using the "int barnum" inside main. Why do u want to have "barnum" as global ?

  6. #6
    Unregistered
    Guest
    Yey. Thanks very much

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. How can I make this code more elegant?
    By ejohns85 in forum C++ Programming
    Replies: 3
    Last Post: 04-02-2009, 08:55 AM
  2. get keyboard and mouse events
    By ratte in forum Linux Programming
    Replies: 10
    Last Post: 11-17-2007, 04:42 PM
  3. Problem with simple case statements
    By shoobsie in forum C Programming
    Replies: 2
    Last Post: 05-08-2006, 08:39 AM
  4. opengl program as win API menu item
    By SAMSAM in forum Game Programming
    Replies: 1
    Last Post: 03-03-2003, 06:48 PM
  5. error with code
    By duffy in forum C Programming
    Replies: 8
    Last Post: 10-22-2002, 09:45 PM

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