Simple error that shouldnt be occuring ( at least i think)!

#include <iostream>
using namespace std;

int main(int argc, const char * argv[])
{

int age;
int name;

cout<<" Enter the name of the test subject \n";
cin>>name;

cout<<" What is the age of"<<name<< "\n";
cin>>age;


if (age > 13 && < 19 ) { //if age is greater than 13 and less than 19
cout<<name<<" is a teenager \n";
}

return 0;
}


Thats the code being used in the program. It's basically just a test of the && operator that i was fooling around with since i just learned about it and my coding book told me to write a program using them (im a beginner at this stuff after all). Anyway the program is to just tell you the whether the subject is a child, teenager, adult, or elderly. But for some reason this line of code-
if (age > 13 && < 19 ) {
- is getting an error under the < sign and xcode is portraying to me that it was expecting an expression after it. However that < was part of the actual expression.....
Can someone help me with fixing this and explain why it is happening? It seems to be happening also on all the other statements similar to that with the < operator are getting that error as well (that is the ones in this same program. I dont know if im missing something in the code or i typed it out wrong but if you could figure out whats wrong and explain why its not working or how to fix it, i would greatly appreciate it.
Thanks
- Ryan
closed account (3bfGNwbp)
Change the below code to what I provided.

if (age > 13 && < 19 )

if (age > 13 && age < 19 )

C++ doesn't read if statements the way you think it does.
Last edited on
Oh i see! i cant belive i was so stupid hahah! Ill try that!
_- Ryan
Yeah thanks @ thebeathacker, it worked! Annnnnnnd i found out that it printed out what is the age of 0 instead of the actual name. Lol i forgot to use string but instead used int lol! Anywho thanks for the help!
- Ryan
Topic archived. No new replies allowed.