Help on terminating a program

1
2
3
4
5
6
7
8
  if ((( Year % 4 == 0) && (! ( Year % 100 == 0))) || (( Year % 4 == 0) && (! ( Year % 100 == 0))&&( Year % 400 == 0)))
    {
           cout<<"The Year "<<Year<<" is a leap year!!"<<endl;
    }
    else
    {
           cout<<Year<<" is not a leap year."<<endl;
    }




If I wanted to make it so my program terminates if "Year" is a negative, how exactly would I go about doing that?

Is there a way to terminate out of an if statement if Year is negative?
Last edited on
shameless bump :|
Just test Year<1 before the if.

Your condition (a && b) || (a && b && c) is wrong.
First of all, (a && b) || (a && b && c) is equivalent to just (a && b && c) for all a,b,c. Second, there's no number that's divisible by 400 but not by 100.
< 0 should work i think. As int does for both positive and negative integeres i think
If you are saying to do something like:

1
2
3
4
if(Year<0)
{
 break;
} 



I am not using a for or while loop so I keep getting an error when I use break;
Last edited on
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
    if(Year<0)
    {
         cout<<"Since when can a year be negative?"<<endl;
         
    }

    else if ((Year%4 == 0 && Year%100 != 0) || Year%400 == 0)
    {
  
           cout<<"The Year "<<Year<<" is a leap year!!"<<endl;
    }
    else
    {
           cout<<Year<<" is not a leap year."<<endl;
    }
    cout<<endl;


That is what I changed it too... seems to be working :)
great! :)
Topic archived. No new replies allowed.