Advertisement
BojidarDosev

Is the year leap or not

Nov 19th, 2023
812
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.61 KB | None | 0 0
  1. #include <iostream>
  2. using namespace std;
  3.  
  4. string leap(int y)
  5. {
  6.     if (y % 100 == 0 && y % 400 == 0)
  7.     {
  8.         return "leap";
  9.     }
  10.     else if (y % 100 == 0 && y % 400 != 0)
  11.     {
  12.         return "not leap";
  13.     }
  14.     else if (y % 4 == 0)
  15.     {
  16.         return "leap";
  17.     }
  18.     else if (y % 4 != 0)
  19.     {
  20.         return "not leap";
  21.     }
  22.     else return "error";
  23. }
  24.  
  25. int main()
  26. {
  27.     int y;
  28.     cout << " Insert a year: \n";
  29.     cin >> y;
  30.     cout << " Year is: \n " << leap(y) <<"\n";
  31.     cout << " Insert a year: \n";
  32.     cin >> y;
  33.     cout << " Year is: \n " << leap(y) << "\n";
  34.     cout << " Insert a year: \n";
  35.     cin >> y;
  36.     cout << " Year is: \n " << leap(y) << "\n";
  37. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement