Thread: Need Help!!!

  1. #1
    Registered User
    Join Date
    May 2009
    Posts
    1

    Need Help!!!

    I have just started a programming class and don't really remember some of the previous class and need help I am supposed to create a program that a user will enter the day and it is supposed to return the day in the full format. This is what I have and am not sure where to go from here PLEASE HELP!!!
    Code:
    // 
    #include <iostream>
    using namespace std;
    
    class DayOfTheWeek
    {
    public:
    	void setDay (char);
    	void getDay (char);
    	void printDay (char);
    
    private:
    	char day;
    };
    
    DayOfTheWeek::DayOfTheWeek()
    {
    	day = '';
    }
    
    void DayOfTheWeek::setDay(char day)
    {
    	cin >> day;
    }
    
    void DayOfTheWeek::getDay(char)
    {
    	if (day = Mon);
    	getDay = "Monday";
    	else if (day = Tues);
    	getDay = "Tuesday";
    	else if (day = Wed);
    	getDay = "Wednesday";
    	else if (day = Thu);
    	getDay = "Thursday";
    	else if (day = Fri);
    	getDay = "Friday";
    	else if (day = Sat);
    	getDay = "Saturday";
    	else if (day = Sun);
    	getDay = "Sunday";
    	else
    		getDay = "Error";
    }
    
    void DayOfTheWeek::printDay(char)
    {
    	return getDay;
    }
    
    int main()
    {
    DayOfTheWeek day1;
    DayOfTheWeek day2;
    
    day1.setDay(char);
    day2.setDay(char);
    
    day1.getDay(char);
    day2.getDay(char);
    
    cout << day1.printday(char) << endl;
    cout << day2.printday(char) << endl;
    
    return 0;
    }

  2. #2
    Registered User
    Join Date
    Oct 2006
    Location
    Canada
    Posts
    1,243
    - "a user will enter the day and it is supposed to return the day in the full format" this doesnt mean anything. being in computer science (or any science), you will know that everything is well defined. therefore, you need to tell us what a "day" is and what "a day in the full format" is. sure, we could assume things, but we (i) wont.

    - in the definition of your DayOfTheWeek class, you have a function called "getDay", which one would assume returns the day, however you have declared it void so it does not return a value.

    - in the implementation for the "getDay" function, your logical comparisons such as "day = mon" will assign the value of variable "mon" to variable "day', to do equality comparisons you use "==" not "=". however, since you are comparing strings you dont use equal signs at all, you use the "string.h" library and its string compare functions, look it up. besides this, you are using a variable called "mon" which doesnt exist so the code wouldnt compile. exact same for every other day in this function.

    - the parameter to the "getDay" function you defined as type "char" but didnt give it a name, which is required. also in this function you are doing something like "getDay = <value>" which is completely incorrect.

    - in the "printDay" function, one would assume it would "print" the "day", but you defined it as returning ("get"s) the day, which you cant do anyways because you declared it void.

    - etc, etc


    "I [...] don't really remember some of the previous class" is what you said. youll notice i gave up above, due to the obvious errors and the fact that you arent even compiling your code which would give obvious explanations for how to fix your syntax errors. go back to your notes that you are ignoring, or forgot to make, or check out the intro tutorials on this website to get familiar with c++ and programming.

    edit: i dont mean to sound rude because you are a beginner, but i think what i have stated is very reasonable and i have tried to be helpful. you cant expect to post a block of code, without even compiling it, and expect us to completely rewrite it.
    Last edited by nadroj; 05-02-2009 at 05:15 PM.

Popular pages Recent additions subscribe to a feed