i keep getting 01/01/2367....i need to get 01/01/67
date T; // variable of new class date
T.setdate(1,1,2367);
void date::printconventional()
{
if ( month %26lt; 10)
cout %26lt;%26lt; "0";
else
cout %26lt;%26lt; "";
cout %26lt;%26lt; month %26lt;%26lt; "/";
if ( day %26lt; 10)
cout %26lt;%26lt; "0";
else
cout %26lt;%26lt; "/";
cout %26lt;%26lt; day;
if (year
if ( year %26lt; 10)
cout %26lt;%26lt; "0";
else
cout %26lt;%26lt; "/";
cout %26lt;%26lt; year;
// cout %26lt;%26lt; ( month %26lt; 10 ? "0" / "" ) %26lt;%26lt; month %26lt;%26lt; ":"
// %26lt;%26lt; ( day %26lt; 10 ? "0" / "" ) %26lt;%26lt; day;
}
In c++ how do i get a 4 digit year to show up as 2 digits....ex, i want january 1 2367 to be 01/01/67...?
Use modulo operator:
year % 100
If year is 2367, then 2367 modulo 100 is 67.
Reply:use the setprecision code. See source for examples.
strawberry
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment