I can not figure out the problem with my program. I am extremely knew at this. The error I get is at the last ' } ' of the program it says "Error expected declaration before '}' token" please help?

This is my code

#include <iostream>  //Header Files
#include <fstream>
#include <string>
#include <iomanip>

using namespace std;

int main()

{

bool leapYear( int year);
int DIW(int year); 
int DOW, year, month, day = 0;
int FDOM;
int mDays[]={ 0, 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31 };
int i = 0;

cout<<"Enter a year"<<endl;
cin>>year;

    if( leapYear( year ) == true ) 

    mDays[ 2 ] = 29;

DOW = DIW( year );

cout<<"Please enter the day of January 1st"<<endl;
cin>>day;


bool leapYear(int year);
{
    if (year % 4 ==0)
        return true;
    else
        return false;
}
// Print this year's calendar
for (int month = 0; month < 12; ++month)

    cout << setw(3) << " ";
        if (month == 0)
    cout << "January \n";
    if (month == 1)
cout << "February \n";
    if (month == 2)
cout << "March \n";
    if (month == 3)
cout << "April \n";
    if (month == 4)
cout << "May \n";
    if (month ==5)
cout << "June \n";
    if (month == 6)
cout << "July \n";
    if (month == 7)
cout << "August \n";
    if (month == 8)
cout << "September \n";
    if (month == 9)
cout << "October \n";
    if (month == 10)
cout << "November \n";
    if (month == 11)
cout << "December \n";

cout << "  S  M  T  W  T  F  S \n" << endl;


//Determine where the first day begins
    day = 0;
    for (FDOM; FDOM < day; ++FDOM)

cout << setw(3);

// Print this month's calendar
    for (int mDay = 0; mDay < mDays[month]; ++mDay){
cout << setw(3) << mDay + 1; 
DOW++;}
if (DOW == 7) {
cout << "\n" << setw(3);
DOW = 0;}

if (DOW != 7) {
cout << "\n";

cout << endl;
day = DOW + 1;}


return 0;
    }
}

Recommended Answers

All 3 Replies

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

get this function out of your main function, also indent your code...
Another thing: your program has logic errors inside of it...

#include <iostream>  //Header Files
#include <fstream>
#include <string>
#include <iomanip>
using namespace std;
bool leapYear(int year)
{
    if (year % 4 ==0)
        return true;
    else
        return false;
}
int main(){
    bool leapYear( int year); //what is this?
    int DIW(int year); //what is this? where is this function implemented?
    int DOW, year, month, day = 0;
    int FDOM;
    int mDays[]={ 0, 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31 };
    int i = 0;
    cout<<"Enter a year"<<endl;
    cin>>year;
    if( leapYear( year ) == true )
    mDays[ 2 ] = 29;
//  DOW = DIW( year );
    cout<<"Please enter the day of January 1st"<<endl;
    cin>>day;

    // Print this year's calendar
    for (int month = 0; month < 12; ++month)
        cout << setw(3) << " ";
        if (month == 0)
            cout << "January \n";
        if (month == 1)
            cout << "February \n";
        if (month == 2)
            cout << "March \n";
        if (month == 3)
            cout << "April \n";
        if (month == 4)
            cout << "May \n";
        if (month ==5)
            cout << "June \n";
        if (month == 6)
            cout << "July \n";
        if (month == 7)
            cout << "August \n";
        if (month == 8)
            cout << "September \n";
        if (month == 9)
            cout << "October \n";
        if (month == 10)
            cout << "November \n";
        if (month == 11)
            cout << "December \n";
    cout << "  S  M  T  W  T  F  S \n" << endl;
    //Determine where the first day begins
    day = 0;
    for (; FDOM < day; ++FDOM)
        cout << setw(3);
    // Print this month's calendar
    for (int mDay = 0; mDay < mDays[month]; ++mDay){
        cout << setw(3) << mDay + 1;
        DOW++;
    }
    if (DOW == 7) {
        cout << "\n" << setw(3);
        DOW = 0;
    }
    if (DOW != 7) {
        cout << "\n";
        cout << endl;
        day = DOW + 1;
    }
    return 0;
}

Thank you so much that helped a lot. Is there any help you could point me in for the logic errors in the code?

thanks so much

Look at the comments, and the commented parts of the code. If you could exaplin that lines, maybe I could help you.

bool leapYear( int year); //what is this?
int DIW(int year); //what is this? where is this function implemented?
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.