Thread: easy help

  1. #1
    Registered User
    Join Date
    Dec 2001
    Posts
    4

    Exclamation easy help

    why is not taking outputting the case values 1, 2, or 3
    #include <iostream.h>
    #include <conio.h>

    frompto()
    {
    cout<<"First option\n";
    return 0;
    }
    fromotp()
    {
    cout<<"Second option\n";
    return 0;
    }

    int main()
    {
    char value;

    cout<<"This is the AMAZING program!!\n";

    cout<<"1. Transform Pounds to Ounces\n";
    cout<<"2. Transform Ounces to Pounds\n";
    cout<<"3. Exit the program\n";
    cin>>value;

    switch (value)
    {
    case 1:
    frompto();
    break;
    case 2:
    fromotp();
    break;
    case 3:
    cout<<"You selected to exit the AMAZING program!!/n";
    return 0;

    }
    return 0;
    }

  2. #2
    Registered User
    Join Date
    Nov 2001
    Posts
    66
    Alright the reason is you initialized value as a char instead of an int. I changed and it worked.

    #include <iostream.h>
    #include <conio.h>

    int frompto();
    int fromotp();

    int frompto()
    {
    cout<<"First option\n";
    return 0;
    }

    int fromotp()
    {
    cout<<"Second option\n";
    return 0;
    }

    int main()
    {
    int value;

    cout<<"This is the AMAZING program!!\n";

    cout<<"1. Transform Pounds to Ounces\n";
    cout<<"2. Transform Ounces to Pounds\n";
    cout<<"3. Exit the program\n";
    cin>>value;

    switch (value)
    {
    case 1:
    frompto();
    break;
    case 2:
    fromotp();
    break;
    case 3:
    cout<<"You selected to exit the AMAZING program!!/n";
    return 0;

    }
    return 0;
    }

  3. #3
    Registered User
    Join Date
    Dec 2001
    Posts
    4

    Talking

    kick ass,thanks dude

  4. #4
    Registered User
    Join Date
    Nov 2001
    Posts
    4
    You are imputing the char '1', '2', or '3' and your switch is 1,2,or3.
    Try switch (value)
    case '1': blah etc...

  5. #5
    Registered User
    Join Date
    Dec 2001
    Posts
    4

    Talking OK

    that worked too, thanks

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Easy String position question...
    By Striph in forum C Programming
    Replies: 4
    Last Post: 05-11-2009, 08:48 PM
  2. Seg fault in easy, easy code
    By lisa1901 in forum C++ Programming
    Replies: 11
    Last Post: 12-10-2007, 05:28 AM
  3. Java vs C to make an OS
    By WOP in forum Tech Board
    Replies: 59
    Last Post: 05-27-2007, 03:56 AM
  4. Easy question, (should be) easy answer... ;-)
    By Unregistered in forum A Brief History of Cprogramming.com
    Replies: 1
    Last Post: 06-12-2002, 09:36 PM
  5. Replies: 20
    Last Post: 05-25-2002, 07:14 PM