I need help with my homework

I am very new to c++ and would like some help writing this out. I am not asking for you to write it out for me. I'm just asking for someone to help me start it.

So the program I have to write is if someone picks the years from 400 to 2400 is it going to be a leap year using the if else statement and here is what i have so far.



begin
Prompt for year in range
Read year
If (year in range)
If (year %4!=0)
Output year is not a leap year
Else (if year%100!=0)
Output year is a leap year
Else (if year%400!=0)
Output year is a century year but not a leap year
Else output year is a century leap year
Else

Output year is out of range

END

// Pre-compiler directives
#include <iostream>
#include <iomanip>
using namespace std;

//main body
int main ()
{
//local identifiers
int Years;
//input module

cout<<"please input year that you would like to check:\t";
cin>>Years;

//computations




I think im doing it right?
Seems like you're on the right track, though an if statement goes:

1
2
3
4
5
6
if (//whatever){
  // Do stuff
}
else if (//Something else){
  //Do other stuff
}


you just put parenthesis in the wrong place in the pseudo-code.

Never heard of a century leap year, but if something has a remainder for 100 it will certainly have a remainder for 400.
ok now im stuck here and have no clue lol =)


// Pre-compiler directives
#include <iostream>

using namespace std;

LeapYear
if (Year % 4 !=0)
cout<<"Year is not a leap year\t"
else (Year % 100 !=0 )
cout<<"year is also not a leap year\t"
else (Year % 400 !=0)
cout<<"year is a centyrt year but not a leap year"
else output year is a century leap year ;












//main body


int main ()
{
//local identifiers
int Years,LeapYear;
//input module

cout<<"please input year that you would like to check:\t";
cin>>Years;

//output
cout<<"LeapYear"<<endl
First try was better, maybe I'm no good :). All your code should be in main()

I think this will help:

http://www.cplusplus.com/doc/tutorial/control/

It's just general stuff to write your if statements better.



haha thanks for trying =D
If you wanted it to be a continuous program you could write a do while statement that envelopes your main code, so you wont need to reopen the code every time you want to enter a year.
1
2
3
4
do
{
     Run code
}while(Years >= 400 && Years <= 2400)
.
As for the if statements, they didnt seem to make sense. Are you trying to do something like this?
1
2
3
4
5
LeapYear
if(Year % 4 == 0)
   cout << "Year is a leap year";
else
  cout << "Year is NOT a leap year";

and so on.
YES! thank you lol I was confused
Topic archived. No new replies allowed.