Hello Andreiz112dn,
PLEASE ALWAYS USE CODE TAGS (the <> formatting button) when posting code.
It makes it easier to read your code and also easier to respond to your post.
http://www.cplusplus.com/articles/jEywvCM9/
http://www.cplusplus.com/articles/z13hAqkS/
Hint: You can edit your post, highlight your code and press the <> formatting button.
You can use the preview button at the bottom to see how it looks.
To start with line 3:
Try to avoid using
using namespace std;
in your programs it may seem easy now, but
WILL get you in trouble some day.
It is better to learn to qualify what is in the standard name space with "std::" and then to learn what is in the standard name space now while it is easy.
What you are most likely to use for now is "std::cout", "std::cin" and "std::endl". About a week or so of typing this and you will not even notice that you are doing it.
A few blank lines here an there to break thing up makes the code easier to read. As an example:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17
|
int main()
{
int a = 0;
int b = 0;
char err;
char sign;
std::cout << "SIMPLE CALCULATOR VERSION V2 (by andreiz112dn)" << std::endl;
std::cout << "PLEASE ENTER THE SIGN FOR CALC" << std::endl;
std::cout << "SIGNS : (* , / , + , -)" << std::endl;
std::cout << "sign >";
std::cin >> sign;
std::cout << "NUMBER I > ";
std::cin >> a;
std::cout << "NUMBER II > ";
std::cin >> b;
switch (sign)
|
A blank line after line 6 says the "std::cout" is a new section so to speak.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18
|
int main()
{
int a = 0;
int b = 0;
char err;
char sign;
std::cout << "SIMPLE CALCULATOR VERSION V2 (by andreiz112dn)" << std::endl;
std::cout << "PLEASE ENTER THE SIGN FOR CALC" << std::endl;
std::cout << "SIGNS : (* , / , + , -)" << std::endl;
std::cout << "sign >";
std::cin >> sign;
std::cout << "NUMBER I > ";
std::cin >> a;
std::cout << "NUMBER II > ";
std::cin >> b;
switch (sign)
|
You have initialized the "int"s, but not the "char"s.
It is
ALWAYS a good practice and programming to initialize your variables. If your compiler is using the C++11 standards or after the easiest way to initialize variables is with empty {}s, e.g.,
int num{};
. This will initialize the variable to 0 (zero) or 0.0 for a double. A "char" will be initialized to "\0". "std::string"s are empty to start with an do not need initialized. Should you need to you can put a number between the {}s.You can also Initialize an array, e.g.,
int aNumbers[10]{};
. This will initialize all elements of the array to 0 (zero). A use of
int aNumbers[10]{ 1 };
will initial the first element to "1" and the rest of the array to "0". Following the "1" with ", 2 ..." will initialize the array with the numbers that you have used up to the entire array.
Looking over your code it looks OK for now until I get a chance to compile and run it. Then I will most likely have more to say.
One thing I did notice is the condition of the do/while loop. "(1 < 2)" will always be true, so what you have is an endless loop here. Until I dig into the program more I am not sure what to change it to right now.
Hope that helps,
Andy
Edit: