Quantcast

Maximum PC

It is currently Thu Aug 21, 2014 2:33 pm

All times are UTC - 8 hours




Post new topic Reply to topic  [ 2 posts ] 
Author Message
 Post subject: Need help with hw
PostPosted: Wed Jan 28, 2009 11:56 am 
Little Foot
Little Foot

Joined: Sat Feb 11, 2006 11:04 am
Posts: 174
im suppose to write a program that finds out if a year is a leap year or not. But when i run it, it doesnt give me the correct answer. For example i put 1988 and it said its a leap year.

Code:
#include <iostream>

using namespace std;

bool leapYear(int);

int main()
{
   int year;
   cout<<"Enter a year ('0' to exit): ";
   cin>>year;
   
   if (leapYear(year))
      cout<<year <<" is a leap year."<<endl;
   else
      cout<<year <<" is not a leap year." <<endl;
   return 0;
   }

bool leapYear(int year)
{
   if (year%4 !=0)
      return false;
   else if (year % 100 !=0)
      return true;
   else if (year%400 !=0)
      return false;
   else
      return true;
}


Top
  Profile  
 
 Post subject:
PostPosted: Wed Jan 28, 2009 12:28 pm 
Java Junkie
Java Junkie
User avatar

Joined: Mon Jun 14, 2004 10:23 am
Posts: 24222
Location: Granite Heaven
Your algorithm is backwards. See the wiki: LINK


Top
  Profile  
 
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 2 posts ] 

All times are UTC - 8 hours


Who is online

Users browsing this forum: No registered users and 5 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to:  
Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group