57.9k views
3 votes
Write a program that asks the user for a 4-digit year and print out the year and the century number of that year. For example:

1850 is in century 19
1995 is in century 20
2035 is in century 21
Requirements:

Use a class constant IN for a Scanner
Use simple arithmetic operator to do the job
A sample input/output may look like the follows.

Please enter a year (such as 2019): 1850
1850 is in century 19
Note: Please, be aware that the example output above shows where the input should be obtained. However, the way that the Zybook works will not be able to show the input. Specifically speaking, the value after the colon will be the input, but the execution will not show it.

1 Answer

7 votes

Answer:

#include <iostream>

using namespace std;

int main() {

// Get the year from the user

cout << "Please enter a year (such as 2019): ";

int year;

cin >> year;

// Calculate the century

int century = year / 100;

// Print the year and the century

cout << year << " is in century " << century << endl;

return 0;

}

Step-by-step explanation:

User Waxical
by
8.8k points

Related questions