+ 4

Can you fix it ? Leap year teller ?

#include <iostream> using namespace std; int main() { int days; cout<<"Enter Number of days in a year\n"; cin >>days; if(days>363) { if(days%400==0 || (days%100!=0 && days%4==0)) { cout<<"Leap Year!\n"; } else { cout<<"Not leap year!\n"; } } else { cout<<"Invalid Input!\n"<<"Please enter days in a year!\n"; } return 0; }

15th Jun 2018, 5:21 PM
Shehroz Irfan
Shehroz Irfan - avatar
10 Respostas
+ 5
if(days==365) cout << "Not leap"; else if(days == 366) cout << "Leap year"; else cout << "invalid"; // your code is applicable for year number i.e 2018 or 1966 // but you are taking no. of days as input which is causing the error. // replace all if statements with code to prevent this error or take year no. as input.
15th Jun 2018, 5:43 PM
‎ ‏‏‎Anonymous Guy
+ 13
i agreed with hinanawi
16th Jun 2018, 12:57 AM
ZΛRTHΛИ
ZΛRTHΛИ - avatar
+ 5
Amrit Mahendra Joseph wow !! thanks
21st Jun 2018, 6:53 AM
Shehroz Irfan
Shehroz Irfan - avatar
15th Jun 2018, 5:22 PM
Shehroz Irfan
Shehroz Irfan - avatar
+ 4
15th Jun 2018, 5:22 PM
Shehroz Irfan
Shehroz Irfan - avatar
+ 4
hinanawi thanks â˜ș
16th Jun 2018, 7:36 AM
Shehroz Irfan
Shehroz Irfan - avatar
+ 4
hinanawi #include <iostream> using namespace std; int main() { int days; cout<<"Enter number of days\n"; cin>>days; if(days==365) { cout<<"Not a leap Year\n"; } else if(days==366) { cout<<"Its a Leap Year\n"; } else { cout<<"Invalid Input\n"; } return 0; }
16th Jun 2018, 7:48 AM
Shehroz Irfan
Shehroz Irfan - avatar
+ 2
shehroz irfan what Sreejith said, your code should read the year number not number of days in said year
15th Jun 2018, 5:49 PM
hinanawi
hinanawi - avatar
+ 2
shehroz irfan looks good
16th Jun 2018, 8:16 AM
hinanawi
hinanawi - avatar
+ 2
I am very poor in C++, I can help with Java... https://code.sololearn.com/cyl9chLy2vDz/?ref=app
20th Jun 2018, 3:54 PM
Dragon Slayer Xavier
Dragon Slayer Xavier - avatar