Help With a Basic Calc

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
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
#include <iostream>
#include <string>

using namespace std;

int addNumbers();
int subtractNumbers();
int multiplyNumbers();
int divideNumbers();

int num1, num2, ans;

int main()
{
    int yesNo;
    int ansChoice;
    
    do{
    cout << "These are your choices: " << endl;
    cout << "  1. Add" << endl;
    cout << "  2. Subtract" << endl;
    cout << "  3. Multiply" << endl;
    cout << "  4. Divide" << endl;
    cout << "  0. Exit" << endl;
    cin >> ansChoice;
    
    switch(ansChoice)
    {
        case 1:
            addNumbers();
            break;
        case 2:
            subtractNumbers();
            break;
        case 3:
            multiplyNumbers();
            break;
        case 4:
            divideNumbers();
            break;
        case 0:
            cout << "Bye." << endl;
            break;
        default:
            cout << "Bye." << endl;
            break;
    }
    
    cout << "Would you like to do another Calculation(1 for yes, 0 for no): ";
    cin >> yesNo;
    
    }while(yesNo = 0)

}

int addNumbers()
{
    int ans;
    
    cout << "Number: ";
    cin >> num1;
    cout << "Number: ";
    cin >> num2;
    
    ans = num1 + num2;
    
    cout << "Sum: " << ans << endl;
    
    return(ans);
    
}

int subtractNumbers()
{
    int ans;
    
    cout << "Number: ";
    cin >> num1;
    cout << "Number: ";
    cin >> num2;
    
    ans = num1 - num2;
    
    cout << "Difference: " << ans << endl;
    
    return(ans);
    
}

int multiplyNumbers()
{
    int ans;
    
    cout << "Number: ";
    cin >> num1;
    cout << "Number: ";
    cin >> num2;
    
    ans = num1 * num2;
    
    cout << "Product: " << ans << endl;
    
    return(ans);
    
}

int divideNumbers()
{
    int ans;
    
    cout << "Number: ";
    cin >> num1;
    cout << "Number: ";
    cin >> num2;
    
    ans = num1 / num2;
    
    cout << "Quotient: " << ans << endl;
    
    return(ans);
    
}


I'm trying to get it to where it'll do an actual loop until the user is done making calculations.

All help will be very much appreciated!

Thanks Anikan,
You test while(yesNo = 0), using the assignment (=) operator, and not an equality check (==). The assignment operator will return a reference to the number itself (0), which is equal to false in c++. Change this to the == operator. Also, you can probably just check while(yesNo), since a 0 is false and anything else is true (You tell the user to input yes=1 and no=0).
Last edited on
THANK YOU !!!!!!!! I FINALLY ACTUALLY GOT SOMETHING DONE THAT I WANTED TO DOOOOOOO :D
Topic archived. No new replies allowed.