Need help on the code for a program I need to write. Display date in 8 digit format. Need code for month, day, year and date. Must use setw function for proper spacing.
I'm really up against it here. Am in a C++ class but never had any programming in the past. So far we've learned about stuff like the basic structure of a program, cout/cin, iostream.h, commenting the code for so non programmers can understand, identifiers, constructors, objects, system defined-programmer defined, attributes, return 0, int main. Just learning about setw and adding,subtracting, mulitplication and division. About all I know but not totally sure how to put it all together.
It should give a timestamp in the form:
YYYY-MM-DD HH:MM:SS.xxxx
Where:
YYYY = the year in full
MM = the month (a number between 1-12)
DD = the day of the month (a number between 1-31)
HH = hours in 24-hour format (a number between 0-23)
MM = minutes (a number between 0-59)
SS = seconds (a number between 0-59)
xxxx = a fraction of a second to 4 decimal places
Let me know if you have any problems with it, I haven't really put much thought into this answer.
Yea true, I just had that already here and just copied and pasted it without thinking too much. There should still be enough to keep jaypa busy. I'll try not to make too much of a habit of telling people the answers though.
// TYPE YOUR NAME
// A BRIEF PROGRAM DESCRIPTION FOR CHAPTER 2, HOMEWORK 2
// COMMENT THE PREPROCESSOR STATEMENT
#include <iostream.h>
int main( )
{
// COMMENT THE OBJECT (ABOVE THE CODE)
int date;
// COMMENT THE OBJECT (ABOVE THE CODE)
int month;
// COMMENT THE OBJECT (ABOVE THE CODE)
int day;
// COMMENT THE OBJECT (ABOVE THE CODE)
int year;
// OUTPUT A MESSAGE (cout) AND THEN INPUT THE OBJECT (cin)
cout << "Enter the date (format YYYYMMDD): ";
cin >> date;
// COMMENT THE CALCULATION
month = ____________________________________________;
// COMMENT THE CALCULATION
day = ______________________________________________;
// COMMENT THE CALCULATION
year = _____________________________________________;
// OUTPUT THE INFORMATION
cout << month << " " << day << " " << year << endl;