Calculator Program

May 23, 2013 at 4:31pm
Whenever I try to make a call to Calc function it says "no match to call, etc"

I'm using Code::Blocks and GNU GCC Compiler


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 <Windows.h>
#include "conio.h"
using namespace std;


int main()
{
    string choice;
    string Menu = "Menu Screen     Pick a function";
    string cases = "       Case Sensitive!";
    string calc = "Calc";
    cout << Menu + "\n" + cases << endl;
    cout << "" << endl;
    cout << "            " + calc << endl;
    cout << "" << endl;
    cin >> choice;
    system("cls");
    if (choice == "calc" || "Calc"){

          calc ();

        }else{
        cout << "Your choice was not recognized. Redirecting to menu." << endl;
        Sleep(1000);
        system("cls");
        main ();
    }

}

void calc() {
    int Input1;
    string Input2;
    int Input3;
    int Answer;
    cout << "Welcome to the calculator" << endl;
    cout << "Enter the first number" << endl;
    cin >> Input1;
    cout << "Enter / (Divide, + (Add) or - (Minus)" << endl;
    cin >> Input2;
    cout << "Now enter the second number" << endl;
    cin >> Input3;

    if (Input2 == "/"){

        Answer = Input1 / Input3;
        cout << Answer << endl;

    }else if (Input2 == "+"){

            Answer = Input1 + Input3;
            cout << Answer << endl;

        }else if (Input2 == "-"){

                Answer = Input1 + Input3;
                cout << Answer << endl;

            }


}
Last edited on May 23, 2013 at 4:32pm
May 23, 2013 at 4:56pm
Because you have no prototype. put the prototype before the main function.
1
2
3
4
5
6
7
8
9
10
11
void calc();

int main()
{
//stuff
}

void calc()
{
//stuff
}
May 23, 2013 at 6:05pm
in my humble opinion, the problem is not only the function prototype:
In fact, you should not use 'cin >>' to enter a string, but the command 'getline (cin, choice)', there is also a problem of overlap between the call 'string calc' and function 'void calc'
if you make these changes the program works, although it is very slow to boot.
've tried to use 'switch' instead of 'if / else'?

one more thing:
you should use variables of type float, so that the calculator return correct results.
bye

P.S. - you forgot the multiplication
Last edited on May 23, 2013 at 6:12pm
Topic archived. No new replies allowed.