Question
I'm getting some errors with this: -the While loop is not working (the program should keep asking 'Enter a year' until user enters a NEGATIVE
I'm getting some errors with this:
-the While loop is not working (the program should keep asking 'Enter a year' until user enters a NEGATIVE year) -I used %4d because user can only enter 4 digit for year -Some years like 2800 (which IS a leap year)...the program is saying that it's not a leap year --> wrong answer
----------------------------------------------------------------
#include < stdio.h > #include < stdlib.h > #include < stdbool.h >
bool isLeap(int year);
int main(){ int year; while (1) { printf("Enter a year:"); scanf("%4d", &year); if (year < 0){ return 0; } else if (isLeap(year)){ printf("Year %4d is a leap year.", year); } else if (!isLeap(year)) { printf("Year %4d is not a leap year.", year); } } return 0; }
bool isLeap(int year) { if (((year / 4 == 0) && (year / 100 != 0)) || (year / 400 == 0)) return true; return false; }
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started