Assignment 1
Write a program that inputs an integer (in hours). Corresponding to the input integer, the program should output the smallest number of years, months, days, and hours. The order of conversion is based on year, month, day, and then hour. Assumes that all months have 30 days and all years have 365 days. (Note that under this rule a year is not equal to twelve months.) As an example,
Enter a number of hours: 1234
The input corresponds to
0 year(s)
1 month(s)
21 day(s)
10 hour(s)
More input-output samples.
Before sending assignments, make sure that your program passes the above input-output samples.
The input is assumed to be an integer with a size range from 0 to 90000.
The output of the following example is not correct, because the conversion to month should be 1 rather than 0.
Enter a number of hours: 1234
The input corresponds to
0 year(s)
0 month(s)
51 day(s)
10 hour(s)
The outputs of your program should be exactly the same as those in the input-output samples.
Every output character (spaces, newlines, punctuation, and letters) of your program should be identical to those in the input-output samples.
It is recommended that you modify the code template to complete this asssignment.
It is recommended that you use the text editor to open input-output samples and copy the outputs of your program to the same file. In this way, it is easy to verify whether the outputs of your program are identical to those in input-output samples.
Do not modify the string enclosed by double quotes, and do not output extra spaces or line breaks.
cout << variable2 << " year(s)" << endl; // code template
cout << variable2 << "year(s)" << endl; // Ex1
cout << variable2 << " year(s)"; // Ex2
cout << variable2 << " year(s)" << endl; system("pause"); // Ex3
cout << variable2 << " year(s)" << endl; cout << endl; // Ex4
Ex1 is incorrect, because it removes a space from the string enclosed by double quotes.
Ex2 is incorrect, because it removes endl.
Ex3 is incorrect, because it outputs extra line breaks caused by system("pause").
Ex4 is incorrect, because it outputs extra endl.
Suggestions:
Rename variable1~variable5 to meaningful names
For example, you can rename variable1 to input_hours
Remove comments
Typically, if your variable naming is meaningful, you need not to write comments.