what is wrong with this?
i keep getting an error that says
error C2059: syntax error : 'if' &&
error C2059: syntax error : 'else'

int main (void);

void menu(void);
int getChoice(void);

int *year, *day, *month, julianday; 

int dayspermonth[] = {31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31};
int sum_array(int, int dayspermonth[]);

void calendarToJulian(void);
void getCalendarDate(int *month, int *day, int *year);

if (*month == 1)
	calendarToJulian = *year	*day;
else if (*month == 2)
	calendarToJulian = *year	sum_array(dayspermonth, 1) + *day;
else if (*month == 3)
	calendarToJulian = *year	sum_array(dayspermonth, 2) + *day;
else if (*month == 4)
	calendarToJulian = *year	sum_array(dayspermonth, 3) + *day;
else if (*month == 5)
	calendarToJulian = *year	sum_array(dayspermonth, 4) + *day;
else if (*month == 6)
	calendarToJulian = *year	sum_array(dayspermonth, 5) + *day;
else if (*month == 7)
	calendarToJulian = *year	sum_array(dayspermonth, 6) + *day;
else if (*month == 8)
	calendarToJulian = *year	sum_array(dayspermonth, 7) + *day;
else if (*month == 9)
	calendarToJulian = *year	sum_array(dayspermonth, 8) + *day;
else if (*month == 10)
	calendarToJulian = *year	sum_array(dayspermonth, 9) + *day;
else if (*month == 11)
	calendarToJulian = *year	sum_array(dayspermonth, 10) + *day;
else if (*month == 12)
	calendarToJulian = *year	sum_array(dayspermonth, 11) + *day;

void julianToCalendar(void);
void getJulianDate(int julianday, int *year);

if (julianday <= 31)
	julianToCalendar = *year	1	julianday;
else if (julianday <=59)
	julianToCalendar = *year	2	julianday-31;
else if (julianday <=90)
	julianToCalendar = *year	3	julianday-59;
else if (julianday <=120)
	julianToCalendar = *year	4	julianday-90;
else if (julianday <=151)
	julianToCalendar = *year	5	julianday-120;
else if (julianday <=181)
	julianToCalendar = *year	6	julianday-151;
else if (julianday <=212)
	julianToCalendar = *year	7	julianday-181;
else if (julianday <=243)
	julianToCalendar = *year	8	julianday-212;
else if (julianday <=273)
	julianToCalendar = *year	9	julianday-243;
else if (julianday <=304)
	julianToCalendar = *year	10	julianday-273;
else if (julianday <=334)
	julianToCalendar = *year	11	julianday-304;
else if (julianday <=365)
	julianToCalendar = *year	12	julianday-334;

int isLeapYear(int year);
int dayspermonthleap[] = {31, 29, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31};
int sum_array(int, int dayspermonthleap[]);

void calendarToJulian(void);
void getCalendarDate(int *month, int *day, int *year);

if (*month == 1)
	calendarToJulian = *year	*day;
else if (*month == 2)
	calendarToJulian = *year	sum_array(dayspermonthleap, 1) + *day;
else if (*month == 3)
	calendarToJulian = *year	sum_array(dayspermonthleap, 2) + *day;
else if (*month == 4)
	calendarToJulian = *year	sum_array(dayspermonthleap, 3) + *day;
else if (*month == 5)
	calendarToJulian = *year	sum_array(dayspermonthleap, 4) + *day;
else if (*month == 6)
	calendarToJulian = *year	sum_array(dayspermonthleap, 5) + *day;
else if (*month == 7)
	calendarToJulian = *year	sum_array(dayspermonthleap, 6) + *day;
else if (*month == 8)
	calendarToJulian = *year	sum_array(dayspermonthleap, 7) + *day;
else if (*month == 9)
	calendarToJulian = *year	sum_array(dayspermonthleap, 8) + *day;
else if (*month == 10)
	calendarToJulian = *year	sum_array(dayspermonthleap, 9) + *day;
else if (*month == 11)
	calendarToJulian = *year	sum_array(dayspermonthleap, 10) + *day;
else if (*month == 12)
	calendarToJulian = *year	sum_array(dayspermonthleap, 11) + *day;

void julianToCalendar(void);
void getJulianDate(int julianday, int *year);

if (julianday <= 31)
	julianToCalendar = *year	1	julianday;
else if (julianday <=60)
	julianToCalendar = *year	2	julianday-31;
else if (julianday <=91)
	julianToCalendar = *year	3	julianday-60;
else if (julianday <=121)
	julianToCalendar = *year	4	julianday-91;
else if (julianday <=152)
	julianToCalendar = *year	5	julianday-121;
else if (julianday <=182)
	julianToCalendar = *year	6	julianday-152;
else if (julianday <=213)
	julianToCalendar = *year	7	julianday-182;
else if (julianday <=244)
	julianToCalendar = *year	8	julianday-213;
else if (julianday <=274)
	julianToCalendar = *year	9	julianday-244;
else if (julianday <=305)
	julianToCalendar = *year	10	julianday-274;
else if (julianday <=335)
	julianToCalendar = *year	11	julianday-305;
else if (julianday <=366)
	julianToCalendar = *year	12	julianday-335;

FILE *csis;


int main(void) {
	int choice;
	
	csis = fopen("csis.txt", "w");
	do {
		choice = getChoice();
		switch (choice) {
			case 1 : calendarToJulian(); break;
			case 2 : julianToCalendar(); break;
			case 3 : break;
		}
	}
	while (choice !=3);
	return 0;
}

int isLeapYear(int year) {
	return ((!(year % 4) && year % 100) || !(year % 400));
}

Edited 6 Years Ago by jalenamichelle: n/a

Your code should be executed or called within main..Example

int main()
{
if (some_condition)
{

}
else if(some_other_condition)
{

}

return 0
}

You have a whole lot of code that isn't contained within main or any callable function.

#include <iostream>

bool myfunc(const char *s)//function - myfunc starts
{
	if (std::cout << s << std::endl)
	{
		return true;
	}
	else
	{
		return false;
	}
}//function - myfunc ends

unsigned long double_it(unsigned long val)//function - double_it starts
{
	return val * 2;
}//function - double_it ends

int main(void) 
{
	unsigned long ans = 0;

	myfunc("test string");//function call

	ans = double_it(123);//function call

	std::cout << ans << std::endl;

	return 0;
}

Edited 6 Years Ago by gerard4143: n/a

my teacher gave us code to start out with and he included

int main(void);

 

void menu(void);

int getChoice(void);

 

void calendarToJulian(void);

void getCalendarDate(int *month, int *day, int *year);

 

void julianToCalendar(void);

void getJulianDate(int *day, int *year);

 

int isLeapYear(int year);

 

FILE *csis;

 

int main(void) {

    int choice;

   

    fopen_s(&csis, "csis.dat", "w");

    do {

        choice = getChoice();

        switch (choice) {

            case 1 : calendarToJulian(); break;

            case 2 : julianToCalendar(); break;

            case 3 : break;

        }

    }

    while (choice != 3);

    return 0;

}

 

int isLeapYear(int year) {

     return ((!(year % 4) && year % 100) || !(year % 400));

}

so thats how he wants us to start

Yeah, so?

What is int main(void) supposed to do?
How about void menu(void) ?
Is there a reason for int getChoice(void) ?
etc.

So start with what he wants. Figure out what the functions are supposed to do. Add code in short segments. And compile often.

This article has been dead for over six months. Start a new discussion instead.