cin ">>" token undefined

Sep 18, 2016 at 1:36pm
using namespace std;
#include <iostream>

class Person{
public:
int age;
int t;
Person(int initialAge);
void amIOld();
void yearPasses();
};
cin>>initialAge ;
if ( initialAge >=0)
age=initialAge ;
if( age<4|age>30)
int t=t+1;
cout<<"setting age to 0.";
if( t>4)
cout<<"number of test casess exceeded.";
if(age<13)
cout<<"you are young.";
if (age>13&age<=18)
cout<<"you are teenager.";
if (age>18)
cout<<"you are old.";
return 0;

compiler compiled codes and "<<" is undefined. are there any further codes to overcome problem?

Last edited on Sep 18, 2016 at 3:17pm
Sep 18, 2016 at 2:15pm
1
2
int initialAge;
cin >> initialAge;
Sep 18, 2016 at 2:18pm
">>" token undefined again.
Sep 18, 2016 at 2:25pm
@karamelax

Few problems with your code, as it is..

1. You have no main().
Line after your class definition, should be int main() { and the line after return 0;, should be }
2. if( age<4|age>30) should be if( age<4||age>30)
Double '||' for 'OR'.
3. if (age>13&age<=18) should be if (age>13&&age<=18)
Double '&&' for 'AND'.
4. You increase the variable ''t' but it's uninitialized, so it's unknown what the value is.

There are other errors, but they can be addressed later..
Sep 18, 2016 at 3:11pm
my code work only problem is ">>" undefined.

11 C:\Dev-Cpp\Untitled2.cpp expected constructor, destructor, or type conversion before '>>' token
Last edited on Sep 18, 2016 at 3:12pm
Sep 18, 2016 at 3:23pm
@karamelax

Could you then show the entire source code? What you have here, will not compile, as there is no main() function.
Sep 18, 2016 at 3:28pm
with added main()

using namespace std;
#include <iostream>
int main();
int age;
int t;

void amIOld();
void yearPasses(); int initialAge;


cin >> initialAge ;
if ( initialAge >=0)
age=initialAge ;
if( age<4|age>30)
int t=t+1;
cout<<"setting age to 0.";
if( t>4)
cout<<"number of test casess exceeded.";
if(age<13)
cout<<"you are young.";
if (age>13&age<=18)
cout<<"you are teenager.";
if (age>18)
cout<<"you are old.";
return 0;
Sep 18, 2016 at 3:42pm
@karamelax

Even that code will not compile. It still doesn't have a main() function. ( I showed how with problem fix #1, above.

Here is your program, in a correct format, and actually using your Person class, that you defined, but never used.

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
30
31
32
33
34
35
36
37
38
39
40
41
#include <iostream>

using namespace std;

class Person{
public:
	int age;
	int initialAge;
	int t;
	void amIOld(); // Creating and using later ??
	void yearPasses(); // Creating and using later ??
};


int main()
{
	Person You;
	You.t = 0;
	cout << "Please enter your current age." << endl;
	cin >> You.initialAge;
	if (You.initialAge >= 0)
		You.age = You.initialAge;
	if (You.age < 4 || You.age>30)
	{
		You.age=0;
		cout << "setting age to 0.";
		You.t++;
		// Not sure what this is supposed to do
	}
	if (You.t > 4)
		cout << "number of test cases exceeded.";
	if (You.age < 13)
		cout << "You are young.";
	if (You.age > 12 && You.age < 20)
		cout << "You are teenager.";
	if (You.age > 19)
		cout << "You are old.";

	cout << endl << endl;
	return 0;
}
Sep 18, 2016 at 4:05pm
its an online example from a website. Im trying to figure out ">>" undefined problem. Besides code you offered has same ">>" problem. im using devC++
11 C:\Dev-Cpp\Untitled2.cpp expected constructor, destructor, or type conversion before '>>' token


Sep 18, 2016 at 4:20pm
@karamelax

Well, I'm then not sure what you're doing wrong, as I put that source code into my Dev-Cpp (ver 5.11) and it compiled an ran, flawlessly. Good luck on your future programming endeavors.
Sep 18, 2016 at 4:25pm
mine is devc++4.9 i shall upgrade it. thank you and likewise
Topic archived. No new replies allowed.