Thread: Please help me with my c++ homework!

  1. #16
    Registered User
    Join Date
    Oct 2010
    Location
    Cincinnati, Oh
    Posts
    25

    Is this anywhere close guys? I'm stuck

    //----------------------------------------------------------------------------
    //File--------project5.cpp
    //Programmer--
    //Course------CSC115
    //Project-----Project #5
    //Due---------November 4, 2010
    //This program calculates the day of the week on which a chosen date falls.
    //----------------------------------------------------------------------------

    Code:
    #include <iostream>
    using namespace std;
    
    //-----------------------------------------------------
    //Main Program
    //-----------------------------------------------------
    
    int main()
    {
    	int century, month, date, year;
    	char day;
    	
    	day=weekday(day); 
    
    	//------------------------------------------------------------------
    	//Weekday
    	//
    	//This function uses Zeller’s Congruence formula to calculate 
    	//the day of the week on which a chosen date falls.
    	//
    	//Input Parameters
    	//   Century---Two numbers to the left in the year
    	//   Year------Two numbers to the right of the century
    	//   Date-------The number of the day of the month
    	//
    	//Output Parameters
    	//   Day---The specific day of the week in which the date falls
    	//
    	//Return Value:
    	//   Day
    	//-------------------------------------------------------------------
    		
    	void weekday(int century, int month, int date, int year)
    	{
    		century=
    		month=
    		date=
    		year=
    
    		
    		return day;
    	}
    	
    		
    		
    		
    		
    		
    		
    		
    	cout<<"Input the year:";
    	cin>>year;
    	cout<<endl;
    	cout<<"Input the century:";
    	cin>>century;
    	cout<<endl;
    	cout<<"Input the day:";
    	cin>>date;
    	cout<<endl;
    	cout<<"Input the month:";
    	cin>>month;
    	cout<<endl;
    
    	cout<<"Month----"<<month;<<endl;
    	cout<<"Day------"<<date;<<endl;
    	cout<<"Year-----"<<year;<<endl;
    	cout<<"Weekday--"<<day;<<endl;
    	cout<<endl;
    	cout<<"Month----"<<0;<<endl;
    
    	return0;
    }
    Last edited by dmeyers81; 11-01-2010 at 08:12 PM.

  2. #17
    Registered User
    Join Date
    Oct 2010
    Location
    Cincinnati, Oh
    Posts
    25
    I'm not exactly sure where to put the call for the function inside the program. The mod operator is to be used somewhere, and I'm not really sure where that goes either.

  3. #18
    Registered User
    Join Date
    May 2010
    Posts
    4,632
    This code is the definition of the function weekday(). You can not define a function inside another function. Move this code outside of any functions.

    Code:
    	//------------------------------------------------------------------
    	//Weekday
    	//
    	//This function uses Zeller’s Congruence formula to calculate 
    	//the day of the week on which a chosen date falls.
    	//
    	//Input Parameters
    	//   Century---Two numbers to the left in the year
    	//   Year------Two numbers to the right of the century
    	//   Date-------The number of the day of the month
    	//
    	//Output Parameters
    	//   Day---The specific day of the week in which the date falls
    	//
    	//Return Value:
    	//   Day
    	//-------------------------------------------------------------------
    		
    	void weekday(int century, int month, int date, int year)
    	{
    		century=
    		month=
    		date=
    		year=
    
    		
    		return day;
    	}
    Jim

  4. #19
    Registered User
    Join Date
    Oct 2010
    Location
    Cincinnati, Oh
    Posts
    25
    So what would i set the variables inside of the function equal to?

  5. #20
    Registered User
    Join Date
    May 2010
    Posts
    4,632
    You should be passing the values into the function when you call it.

    //Input Parameters
    // Century---Two numbers to the left in the year
    // Year------Two numbers to the right of the century
    // Date-------The number of the day of the month
    //
    Please read the following link. functions


    Jim

  6. #21
    Registered User
    Join Date
    Sep 2010
    Posts
    90
    I'm looking at Post #16:

    dmeyers81, I'm no help here, but I see what I been looking for in your code. I just wanted to say, beautiful indentation. Most of your style is what I will be using for now on. If that's not good enough, "I'm sorry", because it will be my style of indentation.

    Btw: No need to say please and especially using the words "do for me". But many may say that accidently from being under-pressure. I would think if you made it as far as you have on your own, you deserve an complete answer with such things as the link jimblumberg provided to mostly finish-up since you only have one-life-time . You got me on the ball.

    Thank you and Good luck

  7. #22
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    39,659
    > where C is the century (the left-most two digits of the year, for example, 19 if the year is 1948), Y is the year within the century (0-99)
    Why are you ASKING for the century when the program spec clearly asks you for only year, month and day?

    You CALCULATE the century from the year, you don't type it in.

    Baby steps
    A development process
    Code:
    #include <iostream>
    using namespace std;
    int main ( ) {
      int Y,M,D;  // Poor variable names, but it matches the spec
      cin >> Y >> M >> D;
      cout << "Year=" << Y << endl;
      cout << "Month=" << M << endl;
      cout << "Day=" << D << endl;
      return 0;
    }
    Compile it, test it, make sure it works.


    Code:
    #include <iostream>
    using namespace std;
    int main ( ) {
      int Y,M,D;  // Poor variable names, but it matches the spec
      cin >> Y >> M >> D;
      cout << "Year=" << Y << endl;
      cout << "Month=" << M << endl;
      cout << "Day=" << D << endl;
      int C;
      // where C is the century (the left-most two digits of the year,
      C = Y / 100;
      Y = Y % 100;
      cout << "Century=" << C << endl;
      cout << "2 digit year=" << Y << endl;
      return 0;
    }
    Compile it, test it, make sure it works.

    Now you identify the next simple step to perform.
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.

  8. #23
    Registered User
    Join Date
    Oct 2010
    Location
    Cincinnati, Oh
    Posts
    25
    I've been looking at this for hours and my brain hurts i can not figure this out..i have officially decided that programming isnt for me haha...any more suggestions?

    Code:
    #include <iostream>
    using namespace std;
    
    
    //-----------------------------------------------------
    //Main Program
    //-----------------------------------------------------
    
    
    int main ( ) 
    {
      
        int year,month,day;  
      
            cout<<"Input the year:";
    	cin>>year;
    	cout<<endl;
    	cout<<"Input the day:";
    	cin>>date;
    	cout<<endl;
    	cout<<"Input the month:";
    	cin>>month;
    	cout<<endl;	
     
    	int century;
      
            century = year / 100;
            year = year % 100;
        
    	
      	cout<<"Month----"<<month;<<endl;
    	cout<<"Day------"<<date;<<endl;
    	cout<<"Year-----"<<year;<<endl;
    	cout<<"Weekday--"<<day;<<endl;
    	cout<<endl;
    	cout<<"Month----"<<0;<<endl;
    
      return 0;
    }
    
    
    	//------------------------------------------------------------------
    	//Weekday
    	//
    	//This function uses Zeller’s Congruence formula to calculate 
    	//the day of the week on which a chosen date falls.
    	//
    	//Input Parameters
    	//   Century---Two numbers to the left in the year
    	//   Year------Two numbers to the right of the century
    	//   Date-------The number of the day of the month
    	//
    	//Output Parameters
    	//   Day---The specific day of the week in which the date falls
    	//
    	//Return Value:
    	//   Day
    	//-------------------------------------------------------------------
    		
    	void weekday(int century, int year, int month, int date)
    	{
    		day= day + floor((M+1)*26/10) + year + floor(year/4) + floor(century/4) - 2*century) mod 7
    		
    		return day;
    
    	}
    Last edited by dmeyers81; 11-02-2010 at 12:50 PM.

  9. #24
    Registered User
    Join Date
    May 2010
    Posts
    4,632
    What are your error messages when you try to compile??

    Take a close look at your main() function.

    Are all the variables defined?

    ie

    Code:
     int day;
    Hint look at your cin statements.

    A semicolon terminates a statement. Anything after a semicolon is a new statement.

    Do you have any extra semicolons?

    Hint look at your cout statements.

    Remember a variable with the name of day is not the same as a variable with the name of date.

    You must have a closing brace for every opening braces.


    Look through your code and try to answer these questions and see if you can find and fix some of your errors.

    For now let's comment out the following code:

    Code:
    /*               /////////////////////                    Add this line.
    	//------------------------------------------------------------------
    	//Weekday
    	//
    	//This function uses Zeller’s Congruence formula to calculate 
    	//the day of the week on which a chosen date falls.
    	//
    	//Input Parameters
    	//   Century---Two numbers to the left in the year
    	//   Year------Two numbers to the right of the century
    	//   Date-------The number of the day of the month
    	//
    	//Output Parameters
    	//   Day---The specific day of the week in which the date falls
    	//
    	//Return Value:
    	//   Day
    	//-------------------------------------------------------------------
    		
    	void weekday(int century, int year, int month, int date)
    	{
    		day= day + floor((M+1)*26/10) + year + floor(year/4) + floor(century/4) - 2*century) mod 7
    		
    		return day;
    
    	}
    
    
    */                               //////////////////////////// Add this line here
    Then re-compile your code. Read your error messages and try to understand them. One of the most important pieces of information in the error message is the line number where the error is to be found.

    Jim

  10. #25
    Registered User
    Join Date
    Oct 2010
    Location
    Cincinnati, Oh
    Posts
    25
    error LNK2019: unresolved external symbol _main referenced in function ___tmainCRTStartup
    1>C:\Users\Dillon\Documents\Visual Studio 2005\Projects\project5\Debug\project5.exe : fatal error LNK1120: 1 unresolved externals
    1>Build log was saved at "file://c:\Users\Dillon\Documents\Visual Studio 2005\Projects\project5\project5\Debug\BuildLog.htm "
    1>project5 - 2 error(s), 0 warning(s)

  11. #26
    Registered User
    Join Date
    Dec 2007
    Posts
    2,675
    Google-ing your error would have brought to this if you clicked "I'm feeling lucky": MSVCRTD.lib(crtexew.obj) : error LNK2019: unresolved external symbol _WinMain@16 referenced in function _WinMainCRTStartup

  12. #27
    Registered User
    Join Date
    May 2010
    Posts
    4,632
    As the link that rags_to_riches supplied states, you need to change your target to a console application.

    Jim

  13. #28
    Registered User
    Join Date
    Oct 2010
    Location
    Cincinnati, Oh
    Posts
    25
    ok so i fixed all of that, but i still do not have the function right....is the function calculating the right thing? and where do i call for it?


    1>------ Rebuild All started: Project: projectfive, Configuration: Debug Win32 ------
    1>Deleting intermediate and output files for project 'projectfive', configuration 'Debug|Win32'
    1>Compiling...
    1>projectfive.cpp
    1>c:\users\dillon\documents\visual studio 2005\projects\projectfive\projectfive\projectfive. cpp(36) : error C2064: term does not evaluate to a function taking 0 arguments
    1>Build log was saved at "file://c:\Users\Dillon\Documents\Visual Studio 2005\Projects\projectfive\projectfive\Debug\BuildL og.htm"
    1>projectfive - 1 error(s), 0 warning(s)
    ========== Rebuild All: 0 succeeded, 1 failed, 0 skipped ==========
    Code:
    #include <iostream>
    using namespace std;
    
    
    //-----------------------------------------------------
    //Main Program
    //-----------------------------------------------------
    
    
    int main ( ) 
    {
      
        int year,month,weekday,date;  
      
        cout<<"Input the year:";
    	cin>>year;
    	cout<<endl;
    	cout<<"Input the day:";
    	cin>>date;
    	cout<<endl;
    	cout<<"Input the month:";
    	cin>>month;
    	cout<<endl;	
     
    	int century;
      
    	date=weekday(   );
    
        century = year / 100;
        year = year % 100;
    
    	
      	cout<<"Month----"<<month<<endl;
    	cout<<"Day------"<<date<<endl;
    	cout<<"Year-----"<<year<<endl;
    	cout<<"Weekday--"<<weekday<<endl;
    	cout<<endl;
    	cout<<"Month----"<<0<<endl;
    
      return 0;
    }
    
    
    /*
    	//------------------------------------------------------------------
    	//Weekday
    	//
    	//This function uses Zeller’s Congruence formula to calculate 
    	//the day of the week on which a chosen date falls.
    	//
    	//Input Parameters
    	//   Century---Two numbers to the left in the year
    	//   Year------Two numbers to the right of the century
    	//   Date-------The number of the day of the month
    	//
    	//Output Parameters
    	//   Day---The specific day of the week in which the date falls
    	//
    	//Return Value:
    	//   Day
    	//-------------------------------------------------------------------
    		
    	void weekday(int century,int day, int year, int month, int weekday)
    	{
    		weekday= (day + floor((M+1)*26/10)) + (year + floor(year/4)) + (floor(century/4) - 2*century)) mod 7
    		
    		return weekday;
    	}
    */

  14. #29
    Registered User
    Join Date
    Oct 2010
    Location
    Cincinnati, Oh
    Posts
    25
    I'm pulling my hair out over this and I feel like it shouldn't be that hard.

  15. #30
    Registered User
    Join Date
    Aug 2003
    Posts
    1,218
    Look at how you call weekday in main, then look at the parameters to weeday...something is missing right?

    Also you will want to take note of what you are saying weekday should be returning and what it is actually returning, you have a little miss-match there.

    Edit just now saw you had commented out the definition of weekday. You are very close to solving this. Just do one thing at a time...first add a function called weekday that returns say a 1, compile and make sure it compiles, then add so that function can take 1 argument and make sure it compiles and works. After that make the function take all the arguments you need and make sure it still compiles when you call the function and so on.
    Last edited by Shakti; 11-02-2010 at 05:43 PM.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Homework
    By kermi3 in forum A Brief History of Cprogramming.com
    Replies: 11
    Last Post: 11-03-2001, 04:39 PM
  2. Homework
    By kermi3 in forum C Programming
    Replies: 10
    Last Post: 09-27-2001, 04:49 PM
  3. Homework
    By kermi3 in forum C++ Programming
    Replies: 15
    Last Post: 09-26-2001, 03:16 PM
  4. Homework
    By kermi3 in forum C Programming
    Replies: 0
    Last Post: 09-10-2001, 01:26 PM

Tags for this Thread