Title^
I'm here to teach you about if/else statements. You'll need to at least know how to build a "Hello World" program by including iostream, how endl; works, and how cin works to do this.
using namespace std;
int main()
{
int iFirst;
int iSecond;
int iUseranswer;
cout << "Please put in number one: ";
cin >> iFirst;
cout << "Please put in number two: ";
cin >> iSecond;
cout << "What is " << iFirst << " plus " << iSecond << "?" << endl;
cin >> iUseranswer;
if (iUseranswer == iFirst + iSecond)
{
cout << "YAY!!!11!11 You got it, nyoro." << endl;
system("PAUSE");
return 0;
}else{
cout << "NO! WRONG! GAH!!!!11!!!11!12132" << endl;
system("PAUSE");
return 0;
}
}
Alright, that was a lot, and many of you are probably wondering a few things. I'll try to answer most of your questions below:
*** Why don't iFirst and iSecond in line 16 have quotations around them?***
iFirst and iSecond are what's called *variables.* When the user imputs a number at iFirst and iSecond, the number gets stored in memory. Cout can display these numbers in the window in the same way they display stuff like "What is " on the same line.
***Okay now, how do these "if" statements work?***
As you'll probably noticed, the if statement on line 19 had a bunch of stuff in brackets. if (iUseranswer == iFirst + iSecond) basically says "if the imputted answer is equal to the first number plus the second number, execute the following code". The following "else" statement means "Otherwise, execute *this* code. To explain this better, look at the following snippet:
if(This statement is true)
{
Then do this.
}
else
{
If it doesn't, then do this.
}
***Why is it "==" on line 19 and not "="?***
In C++ = means "assign to". Thus, if it was "if(iUseranswer = iFirst + iSecond)", it would've meant "if(iUseranswer is assigned to iFirst +iSecond)", thus not working.
As you can see, the if statement is one of the building blocks toward making programs in C++ that make decisions.
I hope I explained that clearly. If you have any questions, feel free to post
lol, VB Express is for VB (visual basic...) and C++ Express is for C++.
Go here and go to Visual C++ 2008 and hit download.
Although I think it takes up quite a bit of memory & takes a while to install, so if you want something smaller there's Dev-C++.
I went on chatscape and I guess you already left :P