Dont laugh, strings are killing me

So this is my first post and i know it might seem dumb but I need to ask someone. I'm trying to write a program just to run in CMD and do a simple "what action would you like to perform?" and then jump to the function and perform it. See i can write the functions pretty easily, but my "if" statement seems to not actually compute when i have more than 2 options...works fine if its just 2 though?

-please don't flame me for using system() calls
-don't laugh at me too hard

code is as follows:


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
65
66
67
68
69
70
#include<iostream>
#include<conio.h>

using namespace std;
//problems not here
int addition()
{
    double a1;
    double a2;
    system("CLS");
    cout << "This will add two numbers\n";
    cout << "Please enter the first number:";
    cin >> a1;
    cout << "Please enter the second numeber:";
    cin >> a2;
    double adding= (a1 + a2);
    cout << "The sum is ";
    cout << adding;
    cout << endl;
    
    system("pause");
    return 0;
}
//or here
int subtraction()
{
    cout << "sup";
}
//not here either keep going down
int division()
{
    double d1;
    double d2;
    system("CLS");
    cout << "This will find the mean of two numbers\n";
    cout << "Please enter the first number:";
    cin >> d1;
    cout << "Please enter the second numeber:";
    cin >> d2;
    double division= (d1/d2);
    cout << "the mean is ";
    cout << division;
    cout << endl;
    
    system("pause");
    return 0;
}
//problem is here 
int main()
{
    string s1;
    cout << "What math operation would you like to perform?\n";
    cout << "Type addition, subtraction, or division\n";
    cin  >> s1;
    
    
    if(s1=="Division", "division")
    {
    return division();   
    }
    if(s1=="Addition", "addition")
    {
    return addition();
    }
    if(s1== "Subtraction", "subtraction")
    {
    return subtraction();
    }
    
}
Use
if ( (s1 == "Division") || (s1 == "division") )

and so on
wow you made me look dumb, ill close this out in a second but, so just for the reference putting stuff like (x,y,z) only works for variables then? not like a list of things that it could be?
Last edited on
The associativity of comma operator is left to right. Your expression first evaluate left expression i.e. (s1 == "ABC"), and then 2nd which is a true value.
Topic archived. No new replies allowed.