I am doing an assignment that has to use a class dayType.
The program has to set the day, print the day and return the next day.
I am receiving the error:
--------------------Configuration: Program9 - Win32 Debug--------------------
Compiling...
Program9.cpp
C:\Documents and Settings\Faculdade\ISM3232\Assig9\Program9\Program9.cpp(45) : error C2447: missing function header (old-style formal list?)
Error executing cl.exe.

Program9.exe - 1 error(s), 0 warning(s)

Can somebody help me please ?
I am reading the book 100 times but can figure out what is happening.
Thanks a lot

#include <iostream>
#include <string>

using namespace std;

class dayType
{
public:
    void setDay(char day);
    void nextDay();
    void printDay() const;
    
private:
    string dayofweek[7];
    int current;
    char userEntry;
};

int main();
{
	dayType myDay;
	char day;
	
	cout << "Please enter M for Monday, T for Tuesday, W for Wednesday" << endl;
	cout << "R for Thursday, F for Friday, S for Saturday or U for Sunday" << endl;
	cout << endl;

	cin >> day;  

	myDay.setDay(day); // set the day
	cout << endl;
	myDay.printDay() const; // print the day
	cout << endl;
	myDay.nextDay(); // return the next day
	cout << endl;

	cout << myDay.printDay() << endl;

	return 0;
} // end of main

void dayType::setDay(char day)
{
	if (day = "m" || "M")
	{
		(dayofweek [0] == "MONDAY");
	    current = 1;
		userEntry = day;
	}

	if (day = "t" || "T")
	{
		(dayofweek [1] == "TUESDAY");
	    current = 2;
		userEntry = day;
	}

	if (day = "w" || "W")
	{
		(dayofweek [2] == "WEDNESDAY");
	    current = 3;
		userEntry = day;
	}

	if (day = "r" || "R")
	{
		(dayofweek [3] == "THURSDAY");
	    current = 4;
		userEntry = day;
	}

	if (day = "f" || "F")
	{
		(dayofweek [4] == "FRIDAY");
	    current = 5;
		userEntry = day;
	}

	if (day = "s" || "S")
	{
		(dayofweek [5] == "SATURDAY");
	    current = 6;
		userEntry = day;
	}

	if (day = "u" || "U")
	{
		(dayofweek [6] == "SUNDAY");
	    current = 7;
		userEntry = day;
	}
}

void dayType::nextDay()
{
	{
	current++;
	if (current = 7)
	current = 0;
	}

	{
	current++;
	if (current = 6)
	current = 7;
	}

	{
	current++;
	if (current = 5)
	current = 6;
	}

	{
	current++;
	if (current = 4)
	current = 5;
	}

	{
	current++;
	if (current = 3)
	current = 4;
	}

	{
	current++;
	if (current = 2)
	current = 3;
	}

	{
	current++;
	if (current = 1)
	current = 2;
	}
}

void dayType::printDay() const
{
	cout << "The day is: " << dayofweek << endl;
	printDay();
}

Couple of problems:

if (day = "m" || "M")

must be

if ( day == 'm' || day == 'M' )
because day is a single character. (Even if it were a string you couldn't do a comparison like that, you'd need to use strcmp)

You must specify day once for each comparison. Plus, you want to do double = if you are checking for equality. A single = sets a variable...

The setday and nextday functions may be candidates for a switch. Which would be good because you can have it do something then in the default case if the user inputs something besides a char that corresponds to a day of the week.

OK. Thanks for the explanation. I fixed.
Do you see anything else wrong ?
What am I missing ?
Coulf you please give me a hint ?

A switch inside a function on a class ? Is that OK ?

int main();

How do I get rid of this error:

Deleting intermediate files and output files for project 'Program9 - Win32 Debug'.
--------------------Configuration: Program9 - Win32 Debug--------------------
Compiling...
Program9.cpp
c:\documents and settings\faculdade\ism3232\assig9\program9\program9.cpp(45) : error C2447: missing function header (old-style formal list?)
Error executing cl.exe.

Program9.exe - 1 error(s), 0 warning(s)

Post the offending line or full code..

ahahahahahah

#include <iostream> // library to use cin and cout
#include <string> // library to strings

using namespace std;

class dayType
{
public:
    void setDay(char day);
    void nextDay();
	void printDay() const;
    
private:
    string dayofweek[7];
	int current;
	char userEntry;
};

int main();
{
	dayType myDay; // class named dayType - object named myDay
	char day;
	
	cout << "Please enter M for Monday, T for Tuesday, W for Wednesday" << endl;
	cout << "R for Thursday, F for Friday, S for Saturday or U for Sunday" << endl;
	cout << endl;

	cin >> day;  

	myDay.setDay(day); // set the day
	cout << endl;
	myDay.printDay() const; // print the day
	cout << endl;
	myDay.nextDay(); // return the next day
	cout << endl;

	cout << myDay.printDay() << endl;

	return 0;
} // end of main

void dayType::setDay(char day)
{
	if ( day == 'm' || day == 'M' )
	{
		(dayofweek [0] == "MONDAY");
	    current = 1;
		userEntry = day;
	}

	if ( day == 't' || day == 'T' )
	{
		(dayofweek [1] == "TUESDAY");
	    current = 2;
		userEntry = day;
	}

	if ( day == 'w' || day == 'W' )
	{
		(dayofweek [2] == "WEDNESDAY");
	    current = 3;
		userEntry = day;
	}

	if ( day == 'r' || day == 'R' )
	{
		(dayofweek [3] == "THURSDAY");
	    current = 4;
		userEntry = day;
	}

	if ( day == 'f' || day == 'F' )
	{
		(dayofweek [4] == "FRIDAY");
	    current = 5;
		userEntry = day;
	}

	if ( day == 's' || day == 'S' )
	{
		(dayofweek [5] == "SATURDAY");
	    current = 6;
		userEntry = day;
	}

	if ( day == 'u' || day == 'U' )
	{
		(dayofweek [6] == "SUNDAY");
	    current = 7;
		userEntry = day;
	}
}

void dayType::nextDay()
{
	{
	current++;
	if (current = 7)
	current = 0;
	}

	{
	current++;
	if (current = 6)
	current = 7;
	}

	{
	current++;
	if (current = 5)
	current = 6;
	}

	{
	current++;
	if (current = 4)
	current = 5;
	}

	{
	current++;
	if (current = 3)
	current = 4;
	}

	{
	current++;
	if (current = 2)
	current = 3;
	}

	{
	current++;
	if (current = 1)
	current = 2;
	}
}

void dayType::printDay() const
{
	cout << "The day is: " << dayofweek << endl;
	printDay();
}

A couple of issues:


int main(); should be int main() (no ;)

myDay.printDay() const; should be myDay.printDay();
You can't do this:
cout << myDay.printDay() << endl;

because printDay() does not return anything (it returns void)

Also,

You'll end up with some kind of endless loop/recursion here as you are calling your self inside:
void dayType::printDay() const
{
cout << "The day is: " << dayofweek << endl;
printDay();
}

Thanks !!!
Now is compiling. But as you said, I am having problems with this endless loop.
What should I do to get rid of this endless loop ?

(Think about it, you're calling the printDay function inside the printDay function...when do you think it would end?)

OK. I took it out of the printDay function inside the printDay function...
It solved the endless loop.
Now I am having the output as:

The day is: 0012FEFC

Why is that ?
My if statements are incorrect or my printDay function is not ok ?

void dayType::printDay()
{
    cout << "The day is: " << dayofweek << endl;

}

couple of problems. You never set your dayoftheweek variable. (In your setDay you are checking for equality == instead of seting the variable.

if you are going to have an array of the string class, then I'm assuming you want to print out only one of those elements, so you probably want to print out:
dayoftheweek[#]....

That is correct. I just want to print on day. That is why I am using the string dayofweek to store all the days of the week.
By choosing m or M I want to return MONDAY.
That is also why I created the "current". But is not working !!

#include <iostream> // library to use cin and cout
#include <string> // library to strings

using namespace std;

class dayType
{
public:
    void setDay(char day);
    void nextDay();
	void printDay();
    
private:
    string dayofweek[7];
	int current;
	char userEntry;
	string dayoftheweek;
};

int main()
{
	dayType myDay; // class named dayType - object named myDay
	char day;
	
	// asking input from user
	cout << "Please choose one of the following: " << endl;
	cout << endl;
	cout << "M or m ===> Monday " << endl;
	cout << "T or t ===> Tuesday " << endl;
	cout << "W or w ===> Wednesday " << endl;
	cout << "R or r ===> Thursday " << endl;
	cout << "F or f ===> Friday " << endl;
	cout << "S or s ===> Saturday " << endl;
	cout << "U or u ===> Sunday " << endl;
	cout << endl;

	cout << "Enter HERE ====> ";
	cin >> day;  
	cout << endl;

	myDay.setDay(day); // set the day
	cout << endl;
	myDay.printDay(); // print the day
	cout << endl;
	myDay.nextDay(); // return the next day
	cout << endl;

	return 0;
} // end of main

void dayType::setDay(char day)
{
	if ( day == 'm' || day == 'M' )
	{
		(dayofweek [0] == "MONDAY");
	    current = 0;
		userEntry = day;
	}

	if ( day == 't' || day == 'T' )
	{
		(dayofweek [1] == "TUESDAY");
	    current = 1;
		userEntry = day;
	}

	if ( day == 'w' || day == 'W' )
	{
		(dayofweek [2] == "WEDNESDAY");
	    current = 2;
		userEntry = day;
	}

	if ( day == 'r' || day == 'R' )
	{
		(dayofweek [3] == "THURSDAY");
	    current = 3;
		userEntry = day;
	}

	if ( day == 'f' || day == 'F' )
	{
		(dayofweek [4] == "FRIDAY");
	    current = 4;
		userEntry = day;
	}

	if ( day == 's' || day == 'S' )
	{
		(dayofweek [5] == "SATURDAY");
	    current = 5;
		userEntry = day;
	}

	if ( day == 'u' || day == 'U' )
	{
		(dayofweek [6] == "SUNDAY");
	    current = 6;
		userEntry = day;
	}
}

void dayType::nextDay()
{
	{
	current++;
	if (current = 7)
	current = 0;
	}

	{
	current++;
	if (current = 6)
	current = 7;
	}

	{
	current++;
	if (current = 5)
	current = 6;
	}

	{
	current++;
	if (current = 4)
	current = 5;
	}

	{
	current++;
	if (current = 3)
	current = 4;
	}

	{
	current++;
	if (current = 2)
	current = 3;
	}

	{
	current++;
	if (current = 1)
	current = 2;
	}
}

void dayType::printDay()
{
	cout << "The day is: " << dayofweek[current]<< endl;
}

The result now is "The day is: "

DOES NOT SHOW ANYTHING AFTER "The day is: "

AGAIN,


You're not setting it with ==

dayofweek [1] == "TUESDAY");

must be

dayofweek [1] = "TUESDAY";

..etc..

Hi,

How about this one:

#include <iostream>
#include <string>

using namespace std;

class dayType
{
public:
    void setDay(char day);
    void nextDay();
    void printDay();
    void printTomorrow();

private:
    string dayofweek[7];
    int current;
    char userEntry;
};

int main(void)
{
	dayType myDay;
	char day;
	
	cout << "Please enter M for Monday, T for Tuesday, W for Wednesday" << endl;
	cout << "R for Thursday, F for Friday, S for Saturday or U for Sunday" << endl;

	cin>>day;  

	myDay.setDay(day); // set the day
	myDay.printDay();
	myDay.nextDay(); // return the next day
	myDay.printTomorrow();
	return 0;
} 

inline void dayType::setDay(char day)
{
	if (day == 'm' || day == 'M')
	{
		current = 1;
		dayofweek[current - 1] = "MONDAY";
		userEntry = day;

	}

	if (day == 't' || day == 'T')
	{
	 	current = 2;
		dayofweek[current - 1] = "TUESDAY";
		userEntry = day;
	}

	if (day == 'w' || day == 'W')
	{
		current = 3;
		dayofweek[current - 1] = "WEDNESDAY";
		userEntry = day;
	}

	if (day == 'r' || day == 'R')
	{
		current = 4;
		dayofweek[current - 1] = "THURSDAY";
		userEntry = day;
	}

	if (day == 'f' || day == 'F')
	{
		current = 5;
		dayofweek[current - 1] = "FRIDAY";
		userEntry = day;
	}

	if (day == 's' || day == 'S')
	{
		current = 6;
		dayofweek[current - 1] = "SATURDAY";
		userEntry = day;
	}

	if (day == 'u' || day == 'U')
	{
		current = 7;
		dayofweek[current - 1] = "SUNDAY";
		userEntry = day;
	}
}

inline void dayType::nextDay()
{
	switch(current)
	{
	case 1:
		{
		current++;
		setDay('t');
		break;
		}
	case 2:
		{
		current++;
		setDay('w');
		break;
		}
	case 3:
		{
		current++;
		setDay('r');
		break;
		}
	case 4:
		{
		current++;
		setDay('f');
		break;
		}
	case 5:
		{
		current++;
		setDay('s');
		break;
		}
	case 6:
		{
		current++;
		setDay('u');
		break;
		}
	case 7:
		{
		current = 1;
		setDay('m');
		break;
		}
	}
}

inline void dayType::printDay()
{
	cout<<"Today is: "<<*(dayofweek + (current - 1))<<endl;
}

inline void dayType::printTomorrow()
{
	cout<<"Tomorrow is: "<<*(dayofweek + (current - 1))<<endl;
}
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.