What is the difference in "if" and "else", when should I use which, and why should I use "else" here? (I left the "ifs" in there, by the way, and as far as I can tell it worked perfectly)
int a;
cin >> a;
if (a == 1)
cout << "a is 1";
elseif (a == 2)
cout << "a is 2";
elseif (a == 3)
cout << "a is 3";
//etc... etc...
That is how you should test several conditions.
If you need more than one if for the same purpose (such as checking what number the user typed in) only the first if should actually be "if", and the rest being "else if".
However, to get the most out of understanding this, consider this:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17
int a;
cin >> a;
if (a == 1)
cout << "a is 1";
elseif (a == 2)
{
if (a < 3 && a > 1) //this is a subcondition of the else if.
cout << "a is 2";
}
elseif (a == 3)
{
if (a != 2 && a != 4) // this is a subcondition of the else if.
cout << "a is 3";
}
Angel: i don't reallly understand what the float statment is used for i have already checked forums in english and russian and i don't get any info that im looking for and i do speak a little russian but the books were also translated in some parts where i couldn't even understand and as far as i can tell float = ((rootbeer + icecream) * blender)^2 in other words i want two rootbeer floats lol lame joke sorry. O_o