programming

how can I create a program that will accept 2two integers. the user will also choose among the different operations:
1 for addition
2 for subtraction
3 for multiplication
4 for division
closed account (3qX21hU5)
What do you have so far? What are you having trouble with? What do you understand? What don't you understand? What is the output suppose to look like? What is the output now?

Also please post any code that you have so far (Remember to use code tags when posting http://www.cplusplus.com/articles/jEywvCM9/ ) and if you are getting errors post the errors also.
Last edited on
how can i do that by the use of IF ELSE STATEMENT?
closed account (3qX21hU5)
Google it.

Don't mean to be rude but a short explanation gets a short answer.
closed account (28poGNh0)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
# include <iostream>
# include <conio.h>
using namespace std;

void menu(void)
{
    cout << "Enter a number :" << endl;
    cout << "1 for addition" << endl;
    cout << "2 for subtraction" << endl;
    cout << "3 for multiplication" << endl;
    cout << "4 for division" << endl;
    cout << "q to exit" << endl;
}

int main()
{
    char key = ' ';
    while(true)
    {
        menu();
        key = getch();

        if(key=='q'||key<'1'||key>'4')break;

        int firstNbr,secondNbr;
        cout << "Enter the first number  -> ";cin >> firstNbr;
        cout << "Enter the second number -> ";cin >> secondNbr;

        switch(key)
        {
            case '1':
                cout << "Sum = " << firstNbr + secondNbr << endl;
            break;
            case '2':
                cout << "Sub = " << firstNbr - secondNbr << endl;
            break;
            case '3':
                cout << "Mul = " << firstNbr * secondNbr << endl;
            break;
            case '4':
                cout << "Quo = " << firstNbr / secondNbr << endl;
            break;
            default : cout << "This option does not exist" << endl;
        }
    }
    
    cout << "End of program" << endl;
    
    return 0;
}
Topic archived. No new replies allowed.