I've finally been able to write my first half usefull C++ program there are a few thing I would like to add but at the moment I don't know enough to be able to add them.
I have some problems with the code below, when you choose to add and enter the first number etc. then when the answer is displayed the else statement which I added to the program is executed even though I don't want it to be, any ideas?
Code:#include <iostream> int main() { int unsigned short DoAddOrMinus; int long FirstNumber; int long SecondNumber; std::cout << "What would you like to do?\n"; //This is the code for the menu std::cout << "1 - Add\n2 - Subtract\n\n"; std::cout << "Please make your selection: "; std::cin >> DoAddOrMinus; //This is the if statement which performs addition if (DoAddOrMinus == 1) { std::cout << "\n\nWhat is the first number you want to add: "; std::cin >> FirstNumber; std::cout << "What is the second number you want to add: "; std::cin >> SecondNumber; std::cin.ignore(80,'\n'); std::cout << "\n\n"; std::cout << "The answer is: " << FirstNumber + SecondNumber << "\n"; } //This is the code which preforms subtraction if (DoAddOrMinus == 2) { std::cout << "\n\nWhat is the first number you want to subtract: "; std::cin >> FirstNumber; std::cout << "What is the second number you want to subtract: "; std::cin >> SecondNumber; std::cin.ignore(80,'\n'); std::cout << "\n\n"; std::cout << "The answer is: " << FirstNumber - SecondNumber << "\n"; } //This is the code which is activated when someone does not enter a number from the menu else { std::cout << "You should have entered a number from the menu.\n"; } std::cin.get(); return 0; }



LinkBack URL
About LinkBacks
.


