Using C++ I am trying to have the user select add or subtract and then perform the operation. Please let me me know where i went wrong. Thank You!
#include<iostream>
using namespace std;
int main ()
{
int a;
int b;
int answer;
int choice;
cout << " 1 - Addition ";
cout << " 2 - Subtraction ";
cin >> answer;
{
if(choice==1)
{
cout << "Great, please enter a number...\n";
cin >> a;
cout << "Thanks, now enter a number to add to that...\n";
cin >> b;
(answer = a + b);
cout << "All done, the answer is" << answer << "\n\n";
}
if(choice==2)
{
cout << "Great, please enter a number...\n";
cin >> a;
cout << "Thanks, now enter a number to subtract from that...\n";
cin >> b;
(answer = a - b);
cout << "All done, the answer is" << answer << "\n\n";
}
#include<iostream>
usingnamespace std;
int main ()
{
int a;
int b;
int answer;
int choice;
cout << " 1 - Addition ";
cout << " 2 - Subtraction ";
cin >> choice;
{
if(choice==1) {
cout << "Great, please enter a number...\n";
cin >> a;
cout << "Thanks, now enter a number to add to that...\n";
cin >> b;
(answer = a + b);
cout << "All done, the answer is" << answer << "\n\n";
}
if(choice==2) {
cout << "Great, please enter a number...\n";
cin >> a;
cout << "Thanks, now enter a number to subtract from that...\n";
cin >> b;
(answer = a - b);
cout << "All done, the answer is" << answer << "\n\n";
}
return 0;
}
}
Thank you, that work well, my red light (error) on Code Blocks disappeared, but my blank screen that should pop up asking me to select a choice is not coming up.
do you think i should put cin.get() or system("PAUSE") above the return 0;
I had to just confirm what i said, it opens in Microsoft Visual Studio, but it the console will not open in Codeblocks. So you are right it does work, i just had to let you know you were right.