Error: No match For Operator-

closed account (1vD3vCM9)
im writing my own program, now, i wanted to do a calculator mode,
i did this:
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
64
  #include <iostream>
#include <string>
#include <windows.h>
#include "System.h"
#include "Modes.h"
#include "Dsystem.h"
#include "MyFile.h"
#include "SCalSystem.h"
#include "SCalSystem.h"

using namespace std;

SCalSystem::SCalSystem()
{
    string sum;
    string amb;
    string akb;
    string adb;
string input;
string a;
string b;
cout << "Choose First Number: \n";
cin >> a;
cout << "Choose Second Number: \n";
cin >> b;
sum = a + b;
amb = a - b;
akb = a * b;
adb = a / b;
cout << "-----------------------------------\n";
cout << a << " ? " << b << "\n";
cout << "-----------------------------------\n";
cout << "Replace The ? With:  \n\n";
cout << "1. +\n\n";
cout << "2. -\n\n";
cout << "3. *\n\n";
cout << "4. /\n\n";
cin >> input;
if(input == "1")
{
cout << "-----------------------------------\n";
cout << a << " + " << b << " = " << sum << endl;
cout << "-----------------------------------\n";
}

if(input == "2")
{
cout << "-----------------------------------\n";
cout << a << " - " << b << " = " << amb << endl;
cout << "-----------------------------------\n";
}
if(input == "3")
{
cout << "-----------------------------------\n";
cout << a << " * " << b << " = " << amb << endl;
cout << "-----------------------------------\n";
}
if(input == "4")
{
cout << "-----------------------------------\n";
cout << a << " / " << b << " = " << adb << endl;
cout << "-----------------------------------\n";
}
}

and it gives me the Error:
s Program - V.010\SCalSystem.cpp|27|error: no match for 'operator-' in 'a - b'|
Last edited on
a and b are strings (text) so subtraction doesn't make sense. If you want to carry out arithmetic calculations on them you probably want them to be of type int or double.
closed account (1vD3vCM9)
i see...
thank you!
Topic archived. No new replies allowed.