Welcome to Dream.In.Code
Getting C++ Help is Easy!

Join 131,516 C++ Programmers for FREE! Get instant access to thousands of C++ experts, tutorials, code snippets, and more! There are 1,896 people online right now. Registration is fast and FREE... Join Now!




isleapyear program

 
Reply to this topicStart new topic

isleapyear program

essie1234
post 27 Nov, 2005 - 08:46 PM
Post #1


New D.I.C Head

*
Joined: 25 Nov, 2005
Posts: 6


My Contributions


Need help with this. Its compiling but its printing out nothing. It must be something with the for loop. ANy ideas? This is due in an hour and im just about to throw in the towel... figured id come here first.

Thanks:

CODE
#include <iostream>
using namespace std;

bool isleapyear(int a) {
  return ((a % 4 == 0 && a % 100 != 0) || a % 400 == 0);
}  

int main () {
 
  int x, y;
  cout << "Please enter starting and ending years of a range of years: ";
  cin >> x >> y;
  cout << endl;

  if(x > y){
     cout << "Enter a starting date earlier than the ending date: ";
     cin >> x >> y;
  }
 
  for (int i = 1; i >= x && i <= y; i++){
     if (isleapyear(i)) {
        cout << i << " " << endl;
     }
  }
User is offlineProfile CardPM

Go to the top of the page


Amadeus
post 27 Nov, 2005 - 09:44 PM
Post #2


g++ -o drink whiskey.cpp

Group Icon
Joined: 12 Jul, 2002
Posts: 12,158



Thanked 31 times

Dream Kudos: 25
My Contributions


It's your loop condition...starting at one does not allow loop execution in this case, try changing the loop to:
CODE

 for (int i = x; i <=y; i++){
    if (isleapyear(i)) {
       cout << i << " " << endl;
    }
 }

I tested it with 1900 and 2000...worked for me.
User is offlineProfile CardPM

Go to the top of the page

essie1234
post 28 Nov, 2005 - 07:14 AM
Post #3


New D.I.C Head

*
Joined: 25 Nov, 2005
Posts: 6


My Contributions


Thanks very much smile.gif
User is offlineProfile CardPM

Go to the top of the page

Reply to this topicStart new topic
Time is now: 11/20/08 12:58AM

Live C++ Help!

C++ Tutorials

Reference Sheets

C++ Snippets

Bye Bye Ads

Free DIC T-Shirt

T-Shirt Example

Related Sites

Monthly Drawing

Thumb Drive

Partners

Top Contributors

Top 10 Kudos This Month