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
Code:
#include <iostream>
using namespace std;
int main()
{
int thisisanumber;
cout<<"Please enter a number: ";
cin>> thisisanumber;
cin.ignore();
cout<<"You entered: "<< thisisanumber <<"\n";
cin.get();
}
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
Code:
#include <iostream>
using namespace std;
int main()
{
int firstnum;
int secondnum;
int equals;
char sub;
char add;
char multiply;
char choice;
cout<<"Please choose one:Add Multiply Or Subtract";
cin>>choice;
cin.ignore ();
If (choice == sub); {
cout<<"Please enter a number: ";
cin>> firstnum;
cin.ignore();
cout<<"please enter a number to subtract: ";
cin>> secondnum;
cin.ignore ();
equals = firstnum - secondnum;
cout<<"Your answer is: "<< equals <<"\n";
cin.get(); }
Else (choice == add) {
cout<<"Please enter a number:";
cin>> firstnum;
cin.ignore();
cout<<"Please enter a number to add: ";
cin>> secondnum;
cin.ignore ():
equals = firstnum + secondnum;
cout<<"You answer is:" <<equals <<"/n";
cin.get(); }
}
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.
Thanks.
ps i hope the code tag worked, first time posting.