#include <iostream>
using namespace Std;
int main ()
{
Char name[20];
char gender;
int age;
cout << "Please enter your name, gender (m/f) and age:" <<endl;
CIN >> Name >> gender >> age;
cout << "Name:" <<name <<endl;
cout << "Sex:" <<gender <<endl;
cout << "Birthday:" <<2014-age<<endl;
}
[Email protected] c++]# g++ name.cc
[Email protected] c++]#./a.out
Please enter your name, gender (m/f) and age:
Zhang San M 22
Name: Zhang San
Sex:m
birthday:1992
[Email protected] c++]#
What if the age is less than 0?
{
Char name[20];
char gender;
int age;
cout << "Please enter your name, gender (m/f) and age:" <<endl;
CIN >> name >> gender >> age;
cout << "name:" <<name <<endl;
cout << "Sex:" <<gender <<endl;
if (age>=0)
cout << "born Year: "<<2014-age<<endl;
if (age <0)
{
&NBSP ; cout << "Are you from the future??" "<<endl;
cout << "born in" <<-age<< "years later! "<<endl;
}
}
[Email protected] c++]#./a.out
Please enter your name, gender (m/f) and age:
Machine Cat M-10
Name: Doraemon
Sex:m
Are you from the future??
Born in 10!
IO operations for C + +