>else cout << "th." ;
I doubt you want that period there.
This is a discussion on not to sure within the C++ Programming forums, part of the General Programming Boards category; >else cout << "th." ; I doubt you want that period there....
>else cout << "th." ;
I doubt you want that period there.
Naturally I didn't feel inspired enough to read all the links for you, since I already slaved away for long hours under a blistering sun pressing the search button after typing four whole words! - Quzah
You. Fetch me my copy of the Wall Street Journal. You two, fight to the death - Stewie
And this can be simplified:Code:#include <iostream.h> class date { public: char WeekDay[3]; // Make this 4 characters 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' ; // The above can now be changed to: // strcpy(TodaysDate.WeekDay, "Fri") because you would have enough space // to make the value a string TodaysDate.DayOfMonth = 1 ; TodaysDate.MonthOfYear =5 ; TodaysDate.Year = 1995 ; // Now print it out again cout << "The date is: "; cout << TodaysDate.WeekDay[0] << TodaysDate.WeekDay[1] << TodaysDate.WeekDay[2] ; // And this can simply be: // cout << TodaysDate.WeekDay;
toCode:else { if (TodaysDate.DayOfMonth % 10 == 1) cout << "st" ; else if (TodaysDate.DayOfMonth % 10 == 2) cout << "nd" ; else if (TodaysDate.DayOfMonth % 10 == 3) cout << "rd" ; else cout << "th." ; }
Code:else { int rem = TodaysDate.DayOfMonth % 10; // calc the modulo once if (rem == 1) cout << "st" ; else if (rem == 2) cout << "nd" ; else if (rem == 3) cout << "rd" ; else cout << "th." ; }
Definition: Politics -- Latin, from
poly meaning many and
tics meaning blood sucking parasites
-- Tom Smothers