Calculator problem.

Hi.
I am trying to make my calculator allow the user to input more then 2 numbers, with a choice. So if the user choses 3, the will operate with 3 numbers and so on. I have a code, but I cannot get it working properly. It inly allows me to operate with 2 numbers, even though I choses 3. Can anyone take a look at my code and point me in the right direction? :)

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
  #include <iostream>
#include <math.h>
using namespace std;

long double choice, choice2, num1, num2, num3, num4, num5, result;

int main()
{
while(true)
{
    cout << "\n1. Add\n"
            "2. Subtract\n"
            "3. Divide\n"
            "4. Multiply\n"
            "5. Square root\n"
            "6. Potency\n"
            "7. Logarithm\n"                //This is the choice menu
            "8. Cos\n"
            "9. Sin\n"
            "10. Tan\n"
            "11. Pythagoras\n"
            "12. ABC\n"
            "13. Exit\n"
            "\nWhat would you like to do? ";

    cin >> choice;

if(choice == 13)            //If the user choses 13, the console will break.
    break;

if (choice <= 4);         //The user choses add, subtract, divide or multiply, and need to make a choice.
{
    cout << "\nHow many numbers do you want to operate with? 2,3,4 or 5? ";
    cin >> choice2;

if(choice2 = 2)
{
 cout << "\nYou have chosen to operate with " << choice2 << " numbers, please enter your first number: ";
 cin >> num1;
 cout << "\nNow, enter your second number: ";
 cin >> num2;
}
else if(choice2 = 3)
{
 cout << "\nYou have chosen to operate with " << choice2 << " numbers, please enter your first number: ";
 cin >> num1;
 cout << "Now, enter your second number: ";
 cin >> num2;
 cout << "Your third number: ";
 cin >> num3;
}
else if(choice2 = 4)
{
 cout << "\nYou have chosen to operate with " << choice2 << " numbers, please enter your first number: ";
 cin >> num1;
 cout << "Now, enter your second number: ";
 cin >> num2;
 cout << "Enter your third number: ";
 cin >> num3;
 cout << "Enter your fourth number: ";
 cin >> num4;
}
else if(choice2 = 5)
{
 cout << "\nYou have chosen to operate with " << choice2 << " numbers, please enter your first number: ";
 cin >> num1;
 cout << "Now, enter your second number: ";
 cin >> num2;
 cout << "Enter your third number: ";
 cin >> num3;
 cout << "Enter your fourth number: ";
 cin >> num4;
 cout << "Enter your fifth number: ";
 cin >> num5;
}
if(choice == 1)
    result = num1+num2;
if(choice == 2)
    result = num1-num2;
if(choice == 3)
    result = num1/num2;
if(choice == 4)
    result = num1*num2;

cout << "\nThe result is: " << result << endl;

}
}
}
What you are trying to do does not make sense to me, but I think I see your error
Inside some of your if expressions you use a single equals sign(=) instead of a double (==)

= does variable assignment
== compares two values
Yes, thank you! That fixed it :)

I'm making it possible to add 3 numbers together instead of just 2.
Example: 1+1+1 = 3 instead of just 1+1 = 2.
Topic archived. No new replies allowed.