May 19, 2014 at 1:48am UTC
Hi. I was wondering if I could get another small smidge of tech support.
I'm still working my way through Bucky's C++ tutorials on youtube, and I'm trying to use an elseif statement.. the code is below.
When I get to the elseif, the compiler gives me this error message
'elseif was not declared in this scope'
What does that mean and how do I fix it?
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29
#include <iostream>
#include <cmath>
#include <cstdlib>
#include <cstring>
using namespace std;
int main(){
int answer;
cout << "How old is Ben" << endl;
cin >> answer;
if (answer < 35)
{
cout << "Too young" ;
}
elseif (answer > 35)
{
cout << "Too old" ;
}
else
{
cout << "You are correct!" ;
}
cin.get();
return 0;
}
Last edited on May 19, 2014 at 2:01am UTC
May 19, 2014 at 2:03am UTC
A space between elseif and (answer < 35), or a space between the elseif statements and the curly brackets?
May 19, 2014 at 2:19am UTC
A space between "else" and "if". :) Look at my previous post more carefully.
May 19, 2014 at 9:42am UTC
We often think of else if
as a special type of construct but it's really just an else clause that contains nothing more than an if statement.