write a program that will mimic a calculator

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • janice3
    New Member
    • Mar 2007
    • 7

    #1

    write a program that will mimic a calculator

    please help me....
    using selection structure
    the program should take as input two integers and the operation to be performed, iust as it would be entered into a standard calculator. it should output to the screen the same input, including the operator and the result of the operation. example: input2+2, and output 2+2=4
    thank.
  • sicarie
    Recognized Expert Specialist
    • Nov 2006
    • 4677

    #2
    Originally posted by janice3
    please help me....
    using selection structure
    the program should take as input two integers and the operation to be performed, iust as it would be entered into a standard calculator. it should output to the screen the same input, including the operator and the result of the operation. example: input2+2, and output 2+2=4
    thank.
    Ok, what do you need help with?

    Comment

    • r035198x
      MVP
      • Sep 2006
      • 13225

      #3
      Originally posted by janice3
      please help me....
      using selection structure
      the program should take as input two integers and the operation to be performed, iust as it would be entered into a standard calculator. it should output to the screen the same input, including the operator and the result of the operation. example: input2+2, and output 2+2=4
      thank.
      You may consider using a switch. So what code have you written so far?

      Comment

      • janice3
        New Member
        • Mar 2007
        • 7

        #4
        Originally posted by r035198x
        You may consider using a switch. So what code have you written so far?
        i only know the flowing. i don't know how to use switch.
        Code:
        int answer;
            int num1=0;
            int num2=0;
            char ch = ' ';
            
            cout << "Welcome to the calculator" << endl;
            cout << "Enter your equation as number operation number" << endl;
            cout << "(Example: 3 + 4): ";
           
            cin>>num1>>ch>>num2;
                 cout<<num1<<ch<<num2<<"="<<num1+num2<<endl;
        Last edited by sicarie; Mar 13 '07, 03:43 AM. Reason: Added code tags

        Comment

        • sicarie
          Recognized Expert Specialist
          • Nov 2006
          • 4677

          #5
          Originally posted by janice3
          i only know the flowing. i don't know how to use switch.
          Code:
          int answer;
              int num1=0;
              int num2=0;
              char ch = ' ';
              
              cout << "Welcome to the calculator" << endl;
              cout << "Enter your equation as number operation number" << endl;
              cout << "(Example: 3 + 4): ";
             
              cin>>num1>>ch>>num2;
                   cout<<num1<<ch<<num2<<"="<<num1+num2<<endl;
          Looks great so far. Did you research the switch statement as r0 suggested?

          Comment

          Working...