Comment out the line
and your program should compile without any warnings or errors.Code:// date=weekday( );
Once you have your program compiling with warnings or errors you can tackle your function.
Jim
Comment out the line
and your program should compile without any warnings or errors.Code:// date=weekday( );
Once you have your program compiling with warnings or errors you can tackle your function.
Jim
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; }
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.
Look up a C++ Reference and learn How To Ask Questions The Smart WayOriginally Posted by Bjarne Stroustrup (2000-10-14)
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
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; }
if-else statements go like this:
orCode:if (...) { //as much or little code as you want } else { //as much or little code as you want }or some combination of the twoCode:if (...) //one line of code max else //one line of code max
╔╗╔══╦╗
║║║╔╗║║
║╚╣╚╝║╚╗
╚═╩══╩═╝