So apparently this function receives errors after the first "if" statement saying "uninitialized local variable 'yearEntered' used" although I thought it was initialized when I declared int yearEntered = 0. Any help? Thanks
Line 11, line 12 and 18, why are you redeclaring yearEntered ?
Also, instead of yearEntered = yearEntered + 1, you could have used ++yearEntered or yearEntered++.
As for yearEntered = yearEntered + 4 I think it is better to use
yearEntered += 4
Okay, so it definitely compiles now, which is great, but apparently I set up the loop in a way that I didn't intend. The point of the function is to input a given year and then it returns the next 10 leap years. My isLeapYear function is definitely correct since I tested it, but I suppose something isn't working right with it. I also need it to obviously stop once it returns the next 10 leap years and right now it's going indefinitely. Sorry if this requires another topic post.
#include <iostream>
int main()
{
int year = 0;
std::cout << "Enter a year: ";
std::cin >> year;
year += ( 4 - year % 4 );
for(int i = 0; i < 10; i++)
{
std::cout << i + 1 << ' ' << year << '\n';
year += 4;
}
return 0;
}