Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

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

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

MFDBS 91 3rd Symposium On Mathematical Fundamentals Of Database And Knowledge Base Systems Rostock Germany May 6 9 1991

Authors: Bernhard Thalheim ,Janos Demetrovics ,Hans-Detlef Gerhardt

1991st Edition

3540540091, 978-3540540090

More Books

Students also viewed these Databases questions

Question

b. Where did they come from?

Answered: 1 week ago

Question

c. What were the reasons for their move? Did they come voluntarily?

Answered: 1 week ago

Question

5. How do economic situations affect intergroup relations?

Answered: 1 week ago