Beginner needs help with If Statement

This is a discussion on Beginner needs help with If Statement within the C++ Programming forums, part of the General Programming Boards category; Hi, i recently developed a desire to learn how to program. After asking around, I was told to pick up ...

Beginner needs help with If Statement

Hi, i recently developed a desire to learn how to program. After asking around, I was told to pick up C++ as the programing language to learn. I downloaded the free Microsoft Visuall C++ Express and whipped out the cprograming.com tutorial. In the first tutorial it gives you a basic program

After working this threw a couple times i decided to toy around and wrote a simple program using the base code, but adding an extra line for a second number and then subtracted the two and then gave you an answer. This too worked out fine. After reading the next chapter on If statements, i decided to go back and get more indepth. Setting up a couple different variables and then asking the user to imput what type of math, be it addition subtraction multiplication etc and then execute a series of commands to provide them with a simple answer. So far the code i have writen is such

Since i am new, i stopped after the first two functions and debugged. I keep getting two identical errors when i debug the program. "Error C3861 If identifier not found and Else identifier not found. I tried using the help section of Visual C++ plus provide insight on the error code and it explains how to fix it, in a way that I have not learned yet. So I am hoping somebody out there can spot my mistake and help me correct it.

Ok. Firstly I'm going to say that I appreciate that learning programming is hard. So stick at it!!

Secondly, both C and C++ are both case sensitive, so if isn't the same as If, nor is else the same as Else. It's only the lower case versions which should work (it's likely that they're typedeffec of defined somewhere, but ... )

Now. Look at that for and see if you can see why it doesn't work as you would like

In your code you made characters called add, subtract etc. These aren't initialised in your code (not given initial values), so saying if something == something else will have indefined effects. You could have said:

"Simplicity does not precede complexity, but follows it." -- Alan Perlis
"Testing can only prove the presence of bugs, not their absence." -- Edsger Dijkstra
"The only real mistake is the one from which we learn nothing." -- John Powell

I changed the uppercase If and Else statements, and the program debugged completely. I ran the program and it Asked the opening statement, Please choose oneA)dd (M)ultiply Or (S)ubtract:"

After you enter your choice, the window just closes. Not really sure what to do now, since im just starting to learn, i cant really troubleshoot anything without the debugger telling me where an error is, since i dont know what is right and what is wrong.

If anybody wants to take the time to look it over, ill post the whole code. Its not very long

"Simplicity does not precede complexity, but follows it." -- Alan Perlis
"Testing can only prove the presence of bugs, not their absence." -- Edsger Dijkstra
"The only real mistake is the one from which we learn nothing." -- John Powell

"Simplicity does not precede complexity, but follows it." -- Alan Perlis
"Testing can only prove the presence of bugs, not their absence." -- Edsger Dijkstra
"The only real mistake is the one from which we learn nothing." -- John Powell