Hello anighosh2017,
Welcome to the forum.
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.
In line 2 all you need is
#define WINDOWS
the 1 is not necessary. I would suggest using the
#ifdef
this way:
1 2 3 4 5 6 7
|
#define WINDOWS // <--- Comment out for the POSIX version.
#ifdef WINDOWS
#define CLS system("cls") // <--- No semi-colon
#else
#define CLS system("clear") // <--- No semi-colon
#endif // WINDOWS
|
This method will eliminate the need for the function which I did not see used any where in the program. In the program all you would have to type is
CLS;
. The preprossor will change "CLS" to whichever version of the system call that is needed.
Line 14 can be replaced with
CLS;
.
Line 16 float works, double works better, whereas floats do not always store the decimal portion of a number correctly. The extra byte or two for a double does not make that much difference any more.
Line 27 your first if statement. It is not really need because the entire condition can be handled in the switch. As an idea:
1 2 3 4 5 6 7 8 9
|
case 'A':
case 'a': //Addition
cout << "Enter a First No : ";
cin >> a;
cout << "Enter a Last No : ";
cin >> a1;
t = a + a1;
cout << "The total is : " << t << endl;
break;
|
The "case 'A':" will just fall through to "case 'a'" and execute those instructions until break is reached. The same concept can be used for the other letters leaving the "default" to catch anything that does not match.
The errors you listed:
1 2
|
136 6 [Error] 'else' without a previous 'if'
139 6 [Error] 'else' without a previous 'if'
|
Are because of the
return 0;
on lines 206 and 209. the
return 0;
is not part if the "if" so it comes between the "if" and the "else" leaving an "else" without an "if" error. Lines 206 and 209 are not needed. If they could ever be reached your program would end and I do not think that is what you want.
The last part I noticed
goto a;
. Bad form. A goto statement is very rare occurrence in a program these days because there are better accepted ways to loop back to the top like "do while" or "while" loops. I can have a solution to the goto statements when I work with the program shortly.
Hope that helps,
Andy