Determines if it is Summer Olympics year, U.S. Census year, or both. - C++ Data Type

C++ examples for Data Type:int

Description

Determines if it is Summer Olympics year, U.S. Census year, or both.

Demo Code

#include <iostream>
using namespace std;
int main()/*from  ww w . j  a v  a 2  s.com*/
{
   int year;
   // Ask for a year
   cout << "What is a year for the test? ";
   cin >> year;
   // Test the year
   if (((year % 4)==0) && ((year % 10)==0))
   {
      cout << "Both Olympics and U.S. Census!";
      return 0;
   }
   // Quit program, return to operating system.
   if ((year % 4)==0)
   {
      cout << "Summer Olympics only";
   }
   else
   {
      if ((year % 10)==0)
      {
         cout << "U.S. Census only";
      }
   }
   return 0;
}

Result


Related Tutorials