Thread: Need serious help w/ program! Please help!

  1. #1
    Unregistered
    Guest

    Unhappy Need serious help w/ program! Please help!

    I need help w/ this program. I don't know what to do.

    I need a function to present a menu, send the menu choice to main.

    Menu items are:
    - 1 Add
    - 2 Subtract
    - 3 Multiply
    - 4 Divide

    Main prints out number of choice, bad choice.
    Use Switch.
    Cannot use If statements.

    Here's something:
    ------------------------------------------------------------------------------------
    #include<iostream.h>
    #include<iomanip.h>

    int main()

    {

    int one_digit_menu_choice;
    int first_digit;
    int second_digit;
    int sum;
    int difference;
    int product;
    int quotient;

    cout<<"\n Enter 1 add, 2 subtract, 3 multiply, 4 divide";

    cin>>one_digit_menu_choice;

    while (one_digit_menu_choice!=0)

    {switch (one_digit_menu_choice)

    {
    case 1:
    cout<<"You have chosen choice:"<<one_digit_menu_choice;
    break;
    case 2:
    cout<<"You have chosen choice:"<<one_digit_menu_choice;
    break;
    case 3:
    cout<<"You have chosen choice:"<<one_digit_menu_choice;
    break;
    case 4:
    cout<<"You have chosen choice:"<<one_digit_menu_choice;
    break;
    default:
    cout<<"You have chosen an incorrect choice";
    break;

    }

    cout<<"Please enter first digit.\n";
    cin>>first_digit;

    cout<<"Please enter second digit.\n";
    cin>>second_digit;
    ------------------------------------------------------------------------------------
    This is all I have right now. I'm still working on it. Any help would greatly be appreciated! Thanks!

  2. #2
    Registered User
    Join Date
    Apr 2002
    Posts
    1,571

    Re: Need serious help w/ program! Please help!

    What seems to be the problem?

  3. #3
    Registered User
    Join Date
    Apr 2002
    Posts
    48
    lol for one thing you should add
    Code:
    return 0;
    }
    at the end and maybe it will work . But if that's not the problem I'm working on it right now it'll give me something to do and maybe I'll learn a thing or two from it.
    Hey, you gotta start somewhere

  4. #4
    Registered User
    Join Date
    Apr 2002
    Posts
    48

    Red face here it is

    that wasn't really too hard... I guess I'm getting better (don't even say anything). Here's the code it works fine and it got a face lift to (that is if a console program CAN get a face lift)

    Code:
    #include<iostream.h> 
    #include<iomanip.h> 
    
    int main() 
    
    { 
    
    int choice;
    float dig1;
    float dig2;
    double answer;
    cout<<"1. Add\n2. Subtract\n3. Multiply\n4. Divide\n\nChoice: "; 
    
    cin>>choice;
    
    switch (choice)
    {
    	case 1: 
    	cout<<"\nYou have chosen to add"; 
    	break; 
    	case 2: 
    	cout<<"\nYou have chosen to subtract"; 
    	break; 
    	case 3: 
    	cout<<"\nYou have chosen choice to multiply"; 
    	break; 
    	case 4: 
    	cout<<"\nYou have chosen choice divide"; 
    	break; 
    	default: 
    	cout<<"\nYou have chosen an incorrect choice"; 
    	break;
    }
    
    cout<<"\n\nPlease enter first digit: "; 
    cin>>dig1;
    
    cout<<"Please enter second digit: "; 
    cin>>dig2;
    
    if(choice==1)
    {
    	answer=dig1+dig2;
    }
    if(choice==2)
    {
    	answer=dig1-dig2;
    }
    if(choice==3)
    {
    	answer=dig1*dig2;
    }
    if(choice==4)
    {
    	answer=dig1/dig2;
    }
    
    cout<<"\nThe answer is "<<answer;
    
    return 0;
    }
    Spiffy...
    Hey, you gotta start somewhere

  5. #5
    _B-L-U-E_ Betazep's Avatar
    Join Date
    Aug 2001
    Posts
    1,412
    forever loop one_digit_menu_choice is never changed within the loop
    while (one_digit_menu_choice!=0)

    {switch (one_digit_menu_choice)

    {
    case 1:
    cout<<"You have chosen choice:"<<one_digit_menu_choice;
    break;
    case 2:
    cout<<"You have chosen choice:"<<one_digit_menu_choice;
    break;
    case 3:
    cout<<"You have chosen choice:"<<one_digit_menu_choice;
    break;
    case 4:
    cout<<"You have chosen choice:"<<one_digit_menu_choice;
    break;
    default:
    cout<<"You have chosen an incorrect choice";
    break;

    }
    Last edited by Betazep; 04-15-2002 at 06:23 PM.
    Blue

  6. #6
    _B-L-U-E_ Betazep's Avatar
    Join Date
    Aug 2001
    Posts
    1,412
    >>>that wasn't really too hard... I guess I'm getting better

    nicely done... well written code... good use of [ code] tags.... needs comments

    Good job.
    Blue

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Replies: 4
    Last Post: 02-21-2008, 10:39 AM
  2. Using variables in system()
    By Afro in forum C Programming
    Replies: 8
    Last Post: 07-03-2007, 12:27 PM
  3. BOOKKEEPING PROGRAM, need help!
    By yabud in forum C Programming
    Replies: 3
    Last Post: 11-16-2006, 11:17 PM
  4. Can someome help me with a program please?
    By WinterInChicago in forum C++ Programming
    Replies: 3
    Last Post: 09-21-2006, 10:58 PM
  5. My program, anyhelp
    By @licomb in forum C Programming
    Replies: 14
    Last Post: 08-14-2001, 10:04 PM