### idk what is it

 ``123456789101112`` ``````// Accepts a year // Returns 0 if it is NOT a leap year // Returns 1 if it IS a leap year // Returns 2 if it is out of bounds int is_leapYear(int year) { if (year < 1000) return 2; if (year > 9999) return 2; if (year%4) return 0; // if it is NOT a multiple of 4, it is NOT a leap year if (year%100 == 0 && year%400!=0) return 0; // if it IS a multiple of 100 and NOT a multiple of 400 it is NOT a leap year return 1; // otherwise it IS a leap year }``````
You can take as an example the following code that I have written just now.:)

At least it works.

 ``12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152`` ``````using System; namespace LeapYear { class Program { static bool IsLeapYear(int year) { return (year % 4 == 0 && (year % 100 != 0 || year % 400 == 0)); } static void Main(string[] args) { string yesNo; do { string entry; int year = 0; bool valid; do { Console.Write("\nEnter a four-digits year: "); entry = Console.ReadLine(); valid = int.TryParse(entry, out year) && year > 0 && year.ToString().Length == 4; if ( !valid ) Console.WriteLine( "Error: shall be a four-digits number." + "Try again." ); } while (!valid); Console.WriteLine(); if (IsLeapYear(year)) { Console.WriteLine("{0} is a leap year.", year); } else { Console.WriteLine("{0} is not a leap year.", year); } Console.Write("\nWould you like to continue? (y/n ): "); yesNo = Console.ReadLine(); yesNo = yesNo.ToUpper(); } while (yesNo == "Y"); } } }``````
Last edited on
closed account (3TXyhbRD)
Use code tags and format you code. Thank you.
Your solution was on track, just a few minor errors

 ``123456789101112131415161718192021222324252627282930313233343536`` ``````#include using namespace std; int leapyear (int yr) { if ((yr % 4 == 0) && !(yr % 100 == 0)) return 1; else if (yr % 400 == 0) return 1; return 0; } int main() { const int arraySize = 4; int year[ arraySize ]; cout << "Enter " << arraySize << " four digits years:\n"; for ( int i = 0; i < arraySize; i++ ) { cin >> year[ i ]; if (year[i] > 9999 || year[i] < 1000) { cout <<"That was an incorrect year, make sure it is only 4 digits long" <

 ```\$ ./File Enter 4 four digits years: 999 That was an incorrect year, make sure it is only 4 digits long 2348 2010 10000 That was an incorrect year, make sure it is only 4 digits long 4000 7675 2348 is a leap year. 4000 is a leap year.```
Smac89 (49)
 ``123456789`` `````` for ( int i = 0; i < arraySize; i++ ) { cin >> year[ i ]; if (year[i] > 9999 || year[i] < 1000) { cout <<"That was an incorrect year, make sure it is only 4 digits long" <

I think that in the original post the array was defined that each its element would contain only one digit. It was not defined to contain four years.:)
It is a bad idea to remove original post! Now it is not clear what code is being discussed.
Last edited on
closed account (3TXyhbRD)
I removed the original post via Report. Someone edited to contain only nonsense.
Last edited on
Topic archived. No new replies allowed.