#include <iostream>
usingnamespace std;
int main()
{
int a;
int b;
int answer;
int choice;
char again;
do{
cout << "here are your options" << endl << endl;
cout << "1.Addition" << endl;
cout << "2.subtraction" << endl;
cout << "3.multiplication" << endl;
cout << "4.divison" << endl;
cout << "5.to quit" << endl;
cin >> choice;
switch(choice){
case 1:
cout << "enter two numbers you want to use(press enter after you enter each number): ";
cin >> a >> b;
answer = a + b;
cout << "the answer is: " << a << " + " << b << " = " << answer << endl;
break;
case 2:
cout << "enter two numbers you want to use(press enter after you enter each number): ";
cin >> a >> b;
answer = a - b;
cout << "the answer is: " << a << " - " << b << " = " << answer << endl;
break;
case 3:
cout << "enter two numbers you want to use(press enter after you enter each number): ";
cin >> a >> b;
answer = a * b;
cout << "the answer is: " << a << " * " << b << " = " << answer << endl;
break;
case 4:
cout << "enter two numbers you want to use(press enter after you enter each number): ";
cin >> a >> b;
answer = a / b;
cout << "the answer is: " << a << " / " << b << " = " << answer << endl;
break;
case 5:
cout << "thanks for using this calculator";
return 0;
break;
}
cout << "would you like to restart(y or n)";
cin >> again;
}while(again == 'y' ||again == 'Y');
system("pause");
return 0;
}
Hey, you aren't indenting properly. This is a severe issue and you are going to hate yourself very soon if you don't start indenting your code. Your welcome! Here is how it should look:
#include <iostream>
usingnamespace std;
int main()
{
int a, b, answer, choice;
char again;
do{
cout << "here are your options" << endl << endl;
cout << "1.Addition" << endl;
cout << "2.subtraction" << endl;
cout << "3.multiplication" << endl;
cout << "4.divison" << endl;
cout << "5.to quit" << endl;
cin >> choice;
switch(choice){
case 1:
cout << "enter two numbers you want to use(press enter after you enter each number): ";
cin >> a >> b;
answer = a + b;
cout << "the answer is: " << a << " + " << b << " = " << answer << endl;
break;
case 2:
cout << "enter two numbers you want to use(press enter after you enter each number): ";
cin >> a >> b;
answer = a - b;
cout << "the answer is: " << a << " - " << b << " = " << answer << endl;
break;
case 3:
cout << "enter two numbers you want to use(press enter after you enter each number): ";
cin >> a >> b;
answer = a * b;
cout << "the answer is: " << a << " * " << b << " = " << answer << endl;
break;
case 4:
cout << "enter two numbers you want to use(press enter after you enter each number): ";
cin >> a >> b;
answer = a / b;
cout << "the answer is: " << a << " / " << b << " = " << answer << endl;
break;
case 5:
cout << "thanks for using this calculator";
return 0;
break;
default:
cout << "That is not an option. Please choose an available number." << endl;
break;
}
cout << "Would you like to restart?";
cin >> again;
} while(again == 'y' || again == 'Y');
system("pause");
return 0;
}
Actually, not quite. There is generally only one style for indentation: indenting your code a specified number of spaces or tabs (and yes, this number can vary) every time you go into a deeper block of code.
However, what you probably meant to say is that there are many possible bracketing styles. I stuck with the one he was using.
Trust me moot, you will love yourself if you indent properly.
ok and i use code blocks and devc++....why on dev c++ it works but on code blocks it doesnt. on code blocks the error is on this line#include <iostream>