0% found this document useful (0 votes)
27 views

Medina, John Cedrick M. Bscs - S2: Output

This C++ code allows a user to input a year and will output whether it is a leap year or common year. It uses if/else statements to check the year input by the user against conditions to determine if it is divisible by 4, 100, or 400 to identify if it is a leap year. The code then loops, allowing the user to continuously enter years to check, until they enter 'n' or 'N' to quit.

Uploaded by

Cedrick Medina
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
27 views

Medina, John Cedrick M. Bscs - S2: Output

This C++ code allows a user to input a year and will output whether it is a leap year or common year. It uses if/else statements to check the year input by the user against conditions to determine if it is divisible by 4, 100, or 400 to identify if it is a leap year. The code then loops, allowing the user to continuously enter years to check, until they enter 'n' or 'N' to quit.

Uploaded by

Cedrick Medina
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 3

Medina, John Cedrick M.

BSCS – S2

Output

Code
#include <iostream>
using namespace std;
int main()
{
//Medina, John Cedrick M.
//BSCS - S2
char ans1='y';
bool ans = true;
cout << "The code should output one of two possible messages, which are leap
year or common year.";
while(ans)
{
int year;
cout << "\n\nEnter The year: ";
cin >> year;
if(year % 400 == 0 && year % 4 == 0 )
{
cout << "("<< year << ") is a leap year!";
}
else if (year % 100 == 0)
{
cout << "("<< year << ") is a common year!";
}
else if (year < 1600)
{
cout << "("<< year << ") is a common year!";
}
else if (year % 4 == 0)
{
cout << "("<< year << ") is a leap year!";
}
cout << "\n\nWould you like to try again? y/n: ";
cin >> ans1;
if(ans1 == 'Y'|| ans1 =='y')
{
ans = true;
}
else
{
ans = false;
}
}
return 0;
} }
return 0;
}

You might also like