Please help me with my c++ homework!

This is a discussion on Please help me with my c++ homework! within the C++ Programming forums, part of the General Programming Boards category; Comment out the line Code: // date=weekday( ); and your program should compile without any warnings or errors. Once you ...

  1. #31
    Registered User
    Join Date
    May 2010
    Posts
    2,917
    Comment out the line
    Code:
     // date=weekday(   );
    and your program should compile without any warnings or errors.

    Once you have your program compiling with warnings or errors you can tackle your function.

    Jim

  2. #32
    Registered User
    Join Date
    Oct 2010
    Location
    Cincinnati, Oh
    Posts
    25
    OK now i have absolutely no idea what to do. I feel like I'm really close, but there is a lot of little things that aren't right. This project was due today, but if I turn it in tomorrow working, ill get a better grade than if i turned it in today not working.

    Code:
    #include <iostream>
    using namespace std;
    
    
    //-----------------------------------------------------
    //Main Program
    //-----------------------------------------------------
    
    
    int main ( ) 
    {
      
        int year,month,weekday,day;  
    	char repeat;
    	int Monday=2, Tuesday=3, Wednesday=4, Thursday=5, Friday=6, Saturday=0, Sunday=1;
        int dayofweek;
    	int dayname;
    
    	cout<<"Input the month:";
    	cin>>month;
    		while(month!=0){
    			cin>>day;
    			cin>>year;
    			dayofweek=weekday(month,day,year);
    			dayname(dayofweek);
    	cout<<endl;
            cout<<"Input the day:";
    	cin>>day;
    	cout<<endl; 
    	cout<<"Input the year:";
    	cin>>year;
    	cout<<endl;
    
    
    
    	
      	cout<<"Month----"<<month<<endl;
    	cout<<"Day------"<<day<<endl;
    	cout<<"Year-----"<<year<<endl;
    	cout<<"Weekday--"<<weekday<<endl;
    	cout<<endl;
    	cout<<"Month----"<<0<<endl;
    	
    	
    	
    	cout<<"Would you like to compute another date? (Y/N):";
    	cin>>repeat;
    	cout<<endl;
    	cout<<endl;
    	cout<<"----------------------------------------------------";
    	cout<<endl;
    	cout<<endl;
    
    
    	while (repeat=='Y' || repeat== 'y');
    	cout<<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
    	//-------------------------------------------------------------------
    		
    	 weekday(int month,int day,int year);
    
    	{
    		int c,y,d,m;
    
    		d=day;
    		
    			if(month<=2){
    				m=month+12;
    				year--;
    			}
    			else 
    				m=month;
    		
    		c=year/100;
    		y=year%100;
    
    		weekday= ((day +((m+1)*26/10)) + (year +(y/4)) + ((c/4) - 2*c)) % 7);
    		
    		return weekday;
    	}
    	
    	//-------------------------------------------------------------------
    	//displaydayname 
    	//
    	//This function displays the day of the week using numbers associated 
    	//with the days.
    	//
    	//Input Parameters
    	//	Day Number
    	//
    	//Output Parameters
    	//  Day Name
    	//
    	//Return Value
    	//	None
    	//--------------------------------------------------------------------
    
    		void displaydayname(int daynumber)
    		{
    			if (daynumber==0)
    				cout<<"Saturday";
    			else 
    				(daynumber==1)
    				cout<<"Sunday";
    			else 
    				(daynumber==2)
    				cout<<"Monday";
    			else 
    				(daynumber==3)
    				cout<<"Tuesday";
    			else
    				(daynumber==4)
    				cout<<"Wednesday";
    			else
    				(daynumber==5)
    				cout<<"Thursday";
    			else
    				(daynumber==6)
    				cout<<"Friday";
    
    			return;
    		
    		}

  3. #33
    C++ Witch laserlight's Avatar
    Join Date
    Oct 2003
    Location
    Singapore
    Posts
    22,277
    You made a commendable effort to format your code, but it is still not good enough. When I tried to format it better, I quickly found that you did not place your closing brace for a while loop in the global main function, thus causing the main function to be far longer than you expect.

    Other problems spotted at a glance include missing return types for your functions, and missing if keyword for your if-else chain in your displaydayname function.
    C + C++ Compiler: MinGW port of GCC
    Version Control System: Bazaar

    Look up a C++ Reference and learn How To Ask Questions The Smart Way

  4. #34
    Registered User
    Join Date
    May 2010
    Posts
    2,917
    You are trying to add too much to your program at one time.

    Why are you adding the while statement?

    You first need to get the program to work for a single set of entries.

    Why are you adding another function when you have not figured out how to use the first function?

    You need to start out slowly. Add one small item. Compile, fix any errors. Add another item. Compile, continue until complete.


    Jim

  5. #35
    Registered User
    Join Date
    Oct 2010
    Location
    Cincinnati, Oh
    Posts
    25
    Alright guys this is it. I almost got it but i can't get it to compile. It says there is an illegal if-else statement, and term does not evaluate to a function taking 3 arguments.

    Code:
    #include <iostream>
    using namespace std;
    double weekday(int month,int day,int year);
    void displaydayname(int daynumber);
    //-----------------------------------------------------
    //Main Program
    //-----------------------------------------------------
    
    
    int main ( ) 
    {
      
        int year,month,weekday,day;  
        int daynumber;
    	int dayname;
    
    	cout<<"Input the month:";
    	cin>>month;
    	do{
    		
    		cout<<"Day------";
    		cin>> day;
    		cout<<"Year-----";
    		cin>> year;
    
    		cout<<endl;
    	
    		daynumber = weekday(month, day, year);
    		
    		cout<<"Weekday--";
    		cout<< endl;
    
    		displaydayname (daynumber);
    	
    		cout<<endl;
    		cout<<endl;
    		cout<<"Month----";
    		cin>>month;
    		}while (month > 0); 
    		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
    	//-------------------------------------------------------------------
    		
    	 double weekday(int month,int day,int year)
    	 {
    		int c,y,d,m,z;
    
    		d=day;
    		
    			if(month<=2){
    				m=month+12;
    				year--;
    			else
    				m=month;
    			}
    		c=year/100;
    		y=year%100;
    
    		z = ((day +((m+1)*26/10)) + (year +(y/4)) + ((c/4) - 2*c)) % 7;
    		
    		return z;
    	    }
    	
    	//-------------------------------------------------------------------
    	//displaydayname 
    	//
    	//This function displays the day of the week using numbers associated 
    	//with the days.
    	//
    	//Input Parameters
    	//	Day Number
    	//
    	//Output Parameters
    	//  Day Name
    	//
    	//Return Value
    	//	None
    	//--------------------------------------------------------------------
    
    		void displaydayname(int daynumber)
    		{
    			if (daynumber==0)
    				cout<<"Saturday";
    			else if (daynumber==1)
    				cout<<"Sunday";
    			else if (daynumber==2)
    				cout<<"Monday";
    			else if (daynumber==3)
    				cout<<"Tuesday";
    			else if (daynumber==4)
    				cout<<"Wednesday";
    			else if (daynumber==5)
    				cout<<"Thursday";
    			else if (daynumber==6)
    				cout<<"Friday";
    
    			return;
    		
    		}

  6. #36
    Banned ಠ_ಠ's Avatar
    Join Date
    Mar 2009
    Posts
    687
    if-else statements go like this:
    Code:
    if (...) {
        //as much or little code as you want
    } else { 
        //as much or little code as you want
    }
    or
    Code:
    if (...) 
        //one line of code max
    else
        //one line of code max
    or some combination of the two
    ╔╗╔══╦╗
    ║║║╔╗║║
    ║╚╣╚╝║╚╗
    ╚═╩══╩═╝

Page 3 of 3 FirstFirst 123
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, 05:49 PM
  3. Homework
    By kermi3 in forum C++ Programming
    Replies: 15
    Last Post: 09-26-2001, 04:16 PM
  4. Homework
    By kermi3 in forum C Programming
    Replies: 0
    Last Post: 09-10-2001, 02:26 PM

Tags for this Thread


1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21