Hey, im new to C++ forums and C++ for that matter.
Im 16 years old and want to be a game developer so i made a calculator it took about 30min(a while i know but im a beginner) can someone tell me if what ive done is good code or is it really bad, i dont want to learn bad habits I decided to use a switch because i thought it would fit perfectly for such a basic calculator.
#include <iostream>
using namespace std;
int main ()
{
int equation;
int number1;
int number2;
int answer;
cout << "Calculator v1" << endl;
cout << "Choose an equation [1=add][2=subtract][3=divide][4=multiply]: ";
cin >> equation;
cout << "Enter first number: ";
cin >> number1;
cout << "Enter second number: ";
cin >> number2;
switch (equation){
case 1://addition
answer = number1 + number2;
cout << number1 << " + " << number2 << " = " << answer << endl;
break;
case 2://subtraction
answer = number1 - number2;
cout << number1 << " - " << number2 << " = " << answer << endl;
break;
case 3://division
answer = number1 / number2;
cout << number1 << " / " << number2 << " = " << answer << endl;
break;
case 4://multiplication
answer = number1 * number2;
cout << number1 << " x " << number2 << " = " << answer << endl;
break;
default:
equation, number1, number2, answer = 0;
cout << "Math Error";
}
return 0;
}
Please post advice and let me know how i did,
Thanks.