Sunday, July 26, 2009

C++ Age and birth year (please help)?

okay for c++ it asked me to make 2 options one asked the name and 2 option asks the user age and calculate their birth year.





Can any one help me with the age and birth year

C++ Age and birth year (please help)?
This shouldn't be hard.


#include %26lt;iostream%26gt;


using namespace std;





int ager(int yourAge);


int main()


{


int age;


char name[50];


int year;





cout %26lt;%26lt; "ENTER YOUR FIRST NAME: ";


cin %26gt;%26gt; name;


cout %26lt;%26lt; endl;


cout %26lt;%26lt; "ENTER YOUR AGE: ";


cin %26gt;%26gt; age;





year= ager(age);





cout %26lt;%26lt; "You were born on " %26lt;%26lt; year %26lt;%26lt; ".";











system("PAUSE");


}





int ager(int yourAge)


{


int year = (2007 - yourAge);


return(year);


}





sometimes it can be wrong if someones birthday hasn't arrived.


//HERE IS A FIXED VERSION


#include %26lt;iostream%26gt;


using namespace std;





int ager(int yourAge);


int main()


{


int age;


char name[50];


int year;


int month;





cout %26lt;%26lt; "ENTER YOUR FIRST NAME: ";


cin %26gt;%26gt; name;


cout %26lt;%26lt; endl;


cout %26lt;%26lt; "ENTER YOUR AGE: ";


cin %26gt;%26gt; age;


cout %26lt;%26lt; "What Month Were you Born in?(ex: 1 = January): ";


cin %26gt;%26gt; month;





year= ager(age);


if(month %26gt;=10)


{


year = (year-1);


}


cout %26lt;%26lt; "You were born on " %26lt;%26lt; year %26lt;%26lt; ".";











system("PAUSE");


}





int ager(int yourAge)


{


int year = (2007 - yourAge);


return(year);


}





//If I am learning c++ by myself before college. I feel smarter than students in college.
Reply:age 19 born in 1988 is that what you mean?

florist shop

No comments:

Post a Comment