+ 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; }
10 Réponses
+ 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.
+ 13
i agreed with hinanawi
+ 5
Amrit Mahendra Joseph
wow !! thanks
+ 4
hinanawi ?
+ 4
\/.oz ?
+ 4
hinanawi
thanks ☺
+ 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;
}
+ 2
shehroz irfan what Sreejith said, your code should read the year number not number of days in said year
+ 2
shehroz irfan looks good
+ 2
I am very poor in C++, I can help with Java...
https://code.sololearn.com/cyl9chLy2vDz/?ref=app