Hello all,
I’m a newby practicing C++. I’ve copy this code from a book am reading.
I’m not sure what the *if else* statements and the *switch* statements are used here for.
I also don’t understand what values the modulus (%) operations in the *if* statements are supposed to return.
Here it goes:
If somebody has any idea Thanks.Code:#include <iostream.h> class date { public: char WeekDay[3]; int DayOfMonth; int MonthOfYear; int Year; }; void main() { date TodaysDate; // Store a date TodaysDate.WeekDay[0] = 'F' ; TodaysDate.WeekDay[1] = 'r' ; TodaysDate.WeekDay[2] = 'i' ; TodaysDate.DayOfMonth = 17 ; TodaysDate.MonthOfYear = 11 ; TodaysDate.Year = 1995 ; // Now print it out again cout << "The date is: "; cout << TodaysDate.WeekDay[0] << TodaysDate.WeekDay[1] << TodaysDate.WeekDay[2] ; cout << " The " << TodaysDate.DayOfMonth ; if ((TodaysDate.DayOfMonth = 11) || (TodaysDate.DayOfMonth = 12) || (TodaysDate.DayOfMonth = 13)) cout << "th" ; else if (TodaysDate.DayOfMonth % 10 == 1) cout << "st" ; if (TodaysDate.DayOfMonth % 10 == 2) cout << "nd" ; if (TodaysDate.DayOfMonth % 10 == 3) cout << "rd" ; else cout << "th." ; cout << " of " ; switch (TodaysDate.MonthOfYear) { case 1 : cout << "January" ; break ; case 2 : cout << "February" ; break ; case 3 : cout << "March" ; break ; case 4 : cout << "April" ; break ; case 5 : cout << "May" ; break ; case 6 : cout << "June" ; break ; case 7 : cout << "July" ; break ; case 8 : cout << "August" ; break ; case 9 : cout << "September" ; break ; case 10 : cout <<"October" ; break ; case 11 : cout <<"November" ; break ; case 12 : cout <<"December" ; } cout << ", " << TodaysDate.Year ; }