Logic Issue

Hello this is a program to help kids with math, it is really basic.
I am having issues with the logic from line 78 to line 86.

Please help me out! :D
I used a go to statement because I became very lazy and thought it would be quicker, but now I am stuck and I really want to solve this now. Lol I thought it would be easy but turned out to be a problem.

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
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
#include <iostream>
#include <stdio.h>
using namespace std;
int main()
{   //WRITE DOWN VARIABLES FOR THE PROGRAM TO OUTPUT THE MENU OPTIONS.
    startover:

        const int additionOption=1;
        const int subtractionOption=2;
        const int multiplicationOption=3;
        const int divisionOption=4;

        double number1=0;
        double number2=0;
        double answer=0;

    //PRINT(COUT) OUT THE MENU OPTIONS FOR USER TO READ.
        cout<<"\tInput a number to select the menu option of your choice."<<endl;
        cout<<"\n\n\n";
        cout<<"\t1.Addition\n";
        cout<<"\t2.Subtraction\n";
        cout<<"\t3.Multiplication\n";
        cout<<"\t4.Division\n";
    // ASK USER WHICH OPTION THEY WOULD LIKE TO USE.
        int choice;
        cin>>choice;


switch(choice)
{


    //CREATE ADDITION OPTION
    case additionOption:
        cout<<"Insert two numbers that will be added."<<endl;
            cin>>number1;
            cin>>number2;
                answer= number1+number2;
                    cout<<"Your answer is "<<answer<<"\n";

        break;
    //CREATE SUBTRACTION OPTION
    case subtractionOption:

            cout<<"Insert two numbers that will be subtracted."<<endl;
                cin>>number1;
                cin>>number2;
                    answer= number1-number2;
                        cout<<"Your answer is "<<answer<<"\n";

        break;
    //CREATE MULTIPLICATION OPTION
    case multiplicationOption:

            cout<<"Insert two numbers that will be multiplied."<<endl;
                cin>>number1;
                cin>>number2;
                    answer= number1*number2;
                    cout<<"Your answer is "<<answer<<"\n";
                    break;
    //CREATE DIVISION OPTION
    case divisionOption:

            cout<<"Insert two numbers that will be divided."<<endl;
                cin>>number1;
                cin>>number2;
                    answer=number1/number2;
                    cout<<"Your answer is "<<answer<<"\n";
                    break;

    default:

        cout<<"The numbers you have provided this program do not\n";
        cout<<"correspond with the above menu, please try again or end program.\n"<<endl;
}
    //ASK USER IF THEY WOULD LIKE TO RETRY PROGRAM
    cout<<"Would you like to retry program?"<<endl;
string retry;
cin>>retry;
cin.ignore();
    //IF USER REPLIES YES, THEN RETRY
if(retry=="Yes"||"yes"||"YES")
    goto startover;

else
cout<<"Thank you for using the program, make sure you only use this as a last resort."<<endl;

    //IF USER REPLIES NO, THANK THEM FOR USING PROGRAM/END PROGRAM.
   cin.get();
    return 0;
}
What exactly is the problem?
This is the problem: if(retry=="Yes"||"yes"||"YES")
you ask:
if(retry == "Yes" or "yes"!=0 or "YES"!=0)

you can't write or-statements like this, you have to check each of them seperated:
1
2
3
if(retry=="Yes"||
   retry=="yes"||
   retry=="YES")


Last edited on
@kbw The if else statements are the issue, I input "No" into the program and it restarts the program regardless.
@Gamer2015
So I have to keep declaring them?
What do u mean by "yes"==true?
sorry for the last question I understand it now. Thanks a lot m8 I just ran the code you gave me and it worked.
glad to help

What do u mean by "yes"==true?

This was actually wrong of me.
a statement allways resolves to a true or a false.
everything that does not explicitly compare to a value is compared to be not-equal to 0
so the example above should look like
if(retry == "Yes" or "yes"!=0 or "YES"!=0)

so basically these 2 are equal.
if("hello")
if("hello" != 0)

it's a bit hard to understand with pure text because the type of pure text is const char* (a pointer) so i'll make it with numbers ;)
these 2 are equal.
if(5)
if(5 != 0)
Last edited on
Topic archived. No new replies allowed.