Weegee
Go Weegee!
- Reaction score
- 102
I just have a simple request, what are a few ways to optimize my code? This isn't a homework assignment, this is just me trying to learn how to program again after a 2 year lack of C++ (brace yourselves D
I just want to know if there are better programming methods and habits and if I should stay away from some things. All advice or help is appreciated!
Code:
#include <iostream>
#include <string>
#include <Windows.h>
using namespace std;
int n1;
int n2;
string mode;
int main()
{
cout << " Please enter a number you would like to calculate: \n";
cin >> n1;
cout << "\n Please enter your second number: \n";
cin >> n2;
cout << "\n Please enter the modefier (+,-,x,/): \n";
cin >> mode;
cout << "\n Your answer is: ";
if (mode == "+")
cout << n1+n2;
if (mode == "-")
cout << n1-n2;
if (mode == "x")
cout << n1*n2;
if (mode == "/")
cout << n1/n2;
Sleep(5000);
}
I just want to know if there are better programming methods and habits and if I should stay away from some things. All advice or help is appreciated!