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?
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..
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;
#include <iostream>
usingnamespace 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;
}
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
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.