C++ Logical Operator Summer Olympics year, U.S. Census year, or both

Description

C++ Logical Operator Summer Olympics year, U.S. Census year, or both

#include <iostream>
using namespace std;
int main()/*from   ww w.j  av  a2s  . c  o m*/
{
   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;
}



PreviousNext

Related