Confused with this program.

I'm getting some run time errors with this program. This is a practice program I'm working on. Problem: (Make your calculator program perform computations in a separate function for each type of computation)

Basically, after the user enters the two numbers he wants to be used it asks for what type of operation the user wants to use, and when you enter the operation and hit enter the program ends. I'm not sure where in my program there is a problem and I'm completely stumped. Any help would be greatly appreciated.

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
51
52
53
54
55
56
57
58
59
60
61
62
63
#include <iostream>
#include <string>

using namespace std;

//------Function prototypes---------|
 void add ( int numb1, int numb2);
 void subtract (int numb1, int numb2);
 void multiply (int numb1, int numb);
 void divide (int numb1, int numb2);

 int main()
 {
    int numb1;
    int numb2;
    string operation;

    cout << "Enter the first number and then the second number" << "\n";
    cin >> numb1;
    cin >> numb2;
    cout << "Select the type of operation you want to do: add, subtract, multiply, or divide" << "\n";
    cin >> operation;

    if(operation == "add")
    {
        void add (int numb1, int numb2);
    }
    else if(operation == "subtract")
    {
        void subtract (int numb1, int numb2);
    }
    else if (operation == "multiply")
    {
        void multiply (int numb1, int numb2);
    }
    else if (operation == "divide")
    {
        void divide (int numb1, int numb2);
    }

    return 0;
 }

 //------------------------Arithmetic functions----------------------|
 void add (int numb1, int numb2)
 {
     cout << numb1 << "+" << numb2 << "=" << numb1 + numb2;
 }

void subtract (int numb1, int numb2)
{
    cout << numb1 << "-" << numb2 << "=" << numb1 - numb2;
}

void multiply (int numb1, int numb2)
{
    cout << numb1 << "*" << numb2 << "=" << numb1 * numb2;
}

void divide (int numb1, int numb2)
{
    cout << numb1 << "/" << numb2 << "=" << numb1 / numb2;
}
Please see the forum sticky Console closing down.

Also you might want to check for division by zero.
Go look up how to call functions; currently you are not calling them correctly.
Use a pointer reference for the parameters in your function.
Topic archived. No new replies allowed.