Thread: Parse error

  1. #1
    Registered User
    Join Date
    Apr 2003
    Posts
    1

    Question Parse error

    There is a parse error in my code. The compiler says that line 78 has 'parse error before {'
    Line 78 is in my first if statement on the line with the opening bracket after the line with the else. I would apprciate some help with this.

    #include <iostream>
    #include <conio.h>
    #include <cmath>
    using namespace std;

    // Two value returning function that return days alive
    //and number of leap years
    int DaysAlive(int month, int day, int year);
    int LeapYears(int month, int day, int year);

    // Three void functions that calculate number of days into the physical,
    //emotional and intellectual cycles.
    void Physical(int DaysAlive, int& physicalCycle);
    void Emotional(int DaysAlive, int& emotionalCycle);
    void Intellectual(int DaysAlive, int& intellectualCycle);

    // The end date is May 6, 2003
    const int End_Day = 6;
    const int End_Month = 5;
    const int End_Year = 2003;

    int main()
    {
    int TotalDaysAlive;
    int month;
    int day;
    int year;
    int currentAge;
    int dayssincelastbday;
    int i;
    int imonth;
    char another;
    int pys_cycle;
    int emot_cycle;
    int intell_cycle;
    another = 'y';

    //does user want to enter another birthday?
    while(another=='y')
    {

    // Get month, day and year
    cout << "Enter month: ";
    cin >>month;
    cout << "Enter day: ";
    cin >>day;
    cout << "Enter year: ";
    cin >>year;


    //calling functions
    TotalDaysAlive=DaysAlive(month, day, year);
    Physical(TotalDaysAlive, pys_cycle);
    Emotional(TotalDaysAlive, emot_cycle);
    Intellectual(TotalDaysAlive, intell_cycle);

    cout <<"If you want to enter another birthday type y: ";
    cin >>another;
    }

    //determine current age
    if(month < End_Month)
    {
    currentAge=(End_Year - year);
    }
    else if (month > End_Month)
    {
    currentAge=(End_Year - year)-1;
    }
    else (month==End_Month)
    {
    currentAge=(End_Year - year);
    }


    if(day < End_Day)
    {
    currentAge=(End_Year - year);
    }
    else if(day > End_Day)
    {
    currentAge=(End_Year - year)-1;
    }
    else (day==End_Day)
    {
    currentAge=(End_Year - year);
    }

    //number of days since last birthday
    if(month < End_Month)
    {
    switch(month)
    {
    case 1:
    case 3:
    case 5:
    case 7:
    case 8:
    case 10:
    case 12:
    dayssincelastbday = 31-day;
    break;
    case 2:
    dayssincelastbday = 28-day;
    break;
    case 4:
    case 6:
    case 9:
    case 11:
    dayssincelastbday = 30-day;
    break;
    }
    }

    //loop through middle months
    imonth=month+1;
    for(i=imonth; i < End_Month; i++)
    {
    switch(month)
    {
    case 1:
    case 3:
    case 5:
    case 7:
    case 8:
    case 10:
    case 12:
    dayssincelastbday+=31;
    break;
    case 2:
    dayssincelastbday+=28;
    break;
    case 4:
    case 6:
    case 9:
    case 11:
    dayssincelastbday+=30;
    break;
    }
    }

    getch();
    return 0;
    }

    //definition for leap years funtion, number of leap days alive
    int LeapYears(int month, int day, int year)
    {
    int yearsleap;
    int countleap;
    countleap=0;
    yearsleap=year;

    while(yearsleap < End_Year)
    {
    if ((yearsleap%4)==0)
    {
    countleap ++;
    }
    yearsleap ++;
    }
    }
    //born after Feb 29
    if(month>=3) && ((yearsleap%4)==0))
    {
    countleap--;
    }

    //born before Feb 29
    if(End_Year%4==0)
    {
    if(End_Month==1)
    {
    countleap--1;
    }
    else if(End_Month==2 && (End_Day<=28))
    {
    countleap--;
    }
    else
    {
    countleap ++;
    }
    }
    return countleap;

    //daysalive definitions
    int DaysAlive(int month, int day, int year)
    {

    TotalDaysAlive=currentAge * 365 + countleap + 1 + numberofdayssincelastbday;
    cout << "You have been alive for " <<TotalDaysAlive<<endl;
    }

    //cycle definitions
    Physical(TotalDaysAlive, pys_cycle)
    {
    pys_cycle=(TotalDaysAlive) % 23;
    cout << "Physical Cycle: " <<pys_cycle<<endl;
    }
    Emotional(TotalDaysAlive, emot_cycle)
    {
    emot_cycle=(TotalDaysAlive) % 28;
    cout << "Emotional Cycle: " <<emot_cycle<<endl;
    }
    Intellectual(TotalDaysAlive, intell_cycle)
    {
    intell_cycle=(TotalDaysAlive) % 33;
    cout << "Intellectual Cycle: " <<intell_cycle<<endl;
    }

  2. #2
    Registered User
    Join Date
    Mar 2003
    Location
    UK
    Posts
    170
    > else (month==End_Month)
    is not a valid statment, should be either:
    Code:
    else if (month==End_Month)
    OR
    Code:
    else
    Both will have the same out come in the logic of your code.

    Also the same with:
    > else (day==End_Day)

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Compiling sample DarkGDK Program
    By Phyxashun in forum Game Programming
    Replies: 6
    Last Post: 01-27-2009, 03:07 AM
  2. How to monitor process creation?
    By markiz in forum Windows Programming
    Replies: 31
    Last Post: 03-17-2008, 02:39 PM
  3. Using VC Toolkit 2003
    By Noobwaker in forum Windows Programming
    Replies: 8
    Last Post: 03-13-2006, 07:33 AM
  4. C++ compilation issues
    By Rupan in forum C++ Programming
    Replies: 1
    Last Post: 08-22-2005, 05:45 AM
  5. Couple C questions :)
    By Divx in forum C Programming
    Replies: 5
    Last Post: 01-28-2003, 01:10 AM