I'm very new to C++. I started teaching myself C++ last week, and up until now, I haven't had any real problems. I use Microsoft Visual Studio 2017, and I'm having problems with if and else statements. You see, I'm making this very limited calculator. Basically, the program gives you the 4 basic mathematical operations, and you choose which operation you want to use to calculate by entering either 1, 2, 3, or 4. Then, it runs another program which you can then calculate. (e.g.: 2 is for subtraction, if you enter 2, it will run the subtraction calculator) Here's the code for the program.
#include "stdafx.h"
#include "iostream"
using namespace std;
int main(){
int add = 1;
int sub = 2;
int mul = 3;
int div = 4;
cout << "Extremely Limited C++ Calculator: Enter a number between one and
four to start calculating and press enter."
<< '\n'
<< "LEGEND"
<< '\n' << "1 = Addition"
<< '\n' << "2 = Subtraction"
<< "\n" << "3 = Multiplication"
<< '\n' << "4 = Division"
<< '\n' << "Operation: ";
if (cin >> add) {
system("start C:\\CalculatorApps\\addition.exe");
return 0;
}
if (cin >> sub) {
system("start C:\\CalculatorApps\\subtraction.exe");
return 0;
}
if (cin >> mul) {
system("start C:\\CalculatorApps\\multiplication.exe");
return 0;
}
if (cin >> div) {
system("start C:\\CalculatorApps\\division.exe");
return 0;
}
}
So I have the addition.exe and subtraction.exe done, but the problem is that no matter what number I enter, it will always run addition.exe. In the subtraction calculator, I experimented having the user choose if they wanted to subtract more than 2 numbers, but that also didn't end up working because it was ignoring if statements. I also at one point had an else statement on both the subtraction calculator and the main program that takes you to the calculators that displayed text reading that the number they entered was not a valid choice and to enter a valid choice, but even that was ignored by the program. Now, maybe I didn't look hard enough on the internet, but I couldn't find one that helped me out. If you know the answer, please tell me but in words that I can understand (I am new after all), or please link me to another question that has been answered that will solve my question. Thank you in advanced!