Now here is a wonderful code I made, that tells your age the same as was on your last birthday TILL one day before of your birthday (so computer-like no? but I too happen to think that way when it comes to age!). But, as you can see, the nested else-ifs don't go beyond the first else-if level. And I think this SHOULD work, especially when the first nested else-if works. (Nutty C++.)
One has to resort to if (condition && condition) to make it work.
Now WeaknessForCats explained something about why it won't work but that was in the last thread which was a different topic where I happened to start all this. So please paste your reply here, then I'll respond.
Though the point that should be taken here is that it won't work this way, and which is all that should matter.
Thanks
Would have been nice if these site people could provide an interpreter too!
One has to resort to if (condition && condition) to make it work.
Now WeaknessForCats explained something about why it won't work but that was in the last thread which was a different topic where I happened to start all this. So please paste your reply here, then I'll respond.
Though the point that should be taken here is that it won't work this way, and which is all that should matter.
Thanks
Code:
string name; int day, month, year, b_day, b_month, b_year; cout <<"Enter your first name: "; cin >>name; cout <<"H! " <<name <<", what is the date today? Enter day (1 to 31): "; cin >>day; cout <<"Now enter the month (1 to 12): "; cin >>month; cout <<"And the year? (4 digits): "; cin >>year; cout <<"\nNow input your birth date the same way. Day: "; cin >>b_day; cout <<"Month: "; cin >>b_month; cout <<"Year: "; cin >>b_year; if (month < b_month) cout <<"\nYour age is: " <<year - b_year - 1 <<" as of today on " <<day <<"-" <<month <<"-" <<year <<"."; else if (month == b_month) { if (day < b_day) cout <<"\nYour age is: " <<year - b_year - 1 <<" as of today on " <<day <<"-" <<month <<"-" <<year <<"."; } else if (month == b_month) { if (day == b_day) cout <<"\nHey... you became " <<year - b_year <<" years old today on " <<day <<"-" <<month <<"-" <<year <<"... Happy Birthday!!"; } else cout <<"\nYour age is " <<year - b_year <<" as of today on " <<day <<"-" <<month <<"-" <<year <<".";
Comment