Thread: going back

  1. #1
    Registered User
    Join Date
    Sep 2005
    Posts
    196

    going back

    heres my code
    Code:
    #include<iostream>//cout i think
    using namespace std;
    int main()
    {
    int x;//the x
    int y;//the y
    int input;//another thing
    
    cout<<"1. multiply\n";
    cout<<"2. devide\n";
    cout<<"3. addition\n";
    cout<<"4. subtraction\n";
    cout<<"please provide the number listed\n";
    cin>> input;
    switch ( input )
    {
    case 1:
    cout<<"please provide 2 numbers to be multiplied\n";
    cin>> x >> y ;
    cin.ignore();
    cout<<( x*y );
    cin.get();
    break;
    case 2:
    cout<<"please provide 2 numbers to be devided\n";
    cin>> x >> y ;
    cin.ignore();
    cout<<( x/y );
    cin.get();
    break;
    case 3:
    cout<<"pls provide 2 numbers to be added\n";
    cin>> x >> y ;
    cin.ignore();
    cout<<( x+y );
    cin.get();
    break;
    case 4:
    cout<<"pls provide 2 numbers to be subtracted\n";
    cin>> x >> y ;
    cin.ignore();
    cout<<( x-y );
    cin.get();
    break;
    }
    }
    but the the program ends how i make it so that i can go and choose something else
    Last edited by lilhawk2892; 09-26-2005 at 04:58 AM.

  2. #2
    ^ Read Backwards^
    Join Date
    Sep 2005
    Location
    Earth
    Posts
    282
    Just do a simple loop:
    http://www.cprogramming.com/tutorial/lesson3.html

    And put the prompt to repeat after the switch statement.
    Also, I would put a default switch statement that says that input is not valid, ect.

    *edit*
    Also, a comment on your programming style.
    Do not be afraid to use spaces! It makes it much more readable.
    Last edited by Enahs; 09-25-2005 at 08:02 PM.

  3. #3
    Registered User
    Join Date
    Sep 2005
    Posts
    196
    pls close i now know the answer

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. "if you love someone" :D
    By Carlos in forum A Brief History of Cprogramming.com
    Replies: 12
    Last Post: 10-02-2003, 01:10 AM
  2. UInt to CString and back
    By xlnk in forum Windows Programming
    Replies: 6
    Last Post: 08-27-2003, 03:08 PM
  3. Some woman back ended my car today, and back hurts
    By Terrance in forum A Brief History of Cprogramming.com
    Replies: 19
    Last Post: 08-20-2003, 12:42 AM
  4. Returning a Tree node back to void main()
    By gazza in forum C++ Programming
    Replies: 2
    Last Post: 07-07-2002, 02:48 AM
  5. I am back!
    By Betazep in forum A Brief History of Cprogramming.com
    Replies: 19
    Last Post: 03-02-2002, 06:22 PM