>else cout << "th." ;
I doubt you want that period there.
Printable View
>else cout << "th." ;
I doubt you want that period there.
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." ;
}