I have been doin this calendar program and I am completely stuck on how to finish it.i have put what i have been able to do but i cant figure out the next part.
any help at all will be great. please.
the question says.
the line in main that calls output_month should now be changed to a comment for use later.
1) a strange formula due to zeller calculates the day of the week on which any date after jan 1st 1583 occurs. the formula requires the day of the week, the year and the month to calculate the formula.
day: this will be a number between 1 and 31.
year: this is broken into two parts- the century and the decade.
the century is the first two integers of the year.(century=year/100 using integer divison)
the decade is the last two integers of the year.(century=year%100 using integers)
month: march is 1, april is 2, and so on until december is 10, january is 11 and february 12.
the four values are substituted into the formula:
daycode=(((13*month-1)/5)+(decade/4)+(century/4)+decade+day-(2*century))%7
the result of this formula is an integer value for daycode in the range 0 to 6 inclusive.the daycode 0 represents sunday, 1 represents monday etc.
design a function called zeller, called from main,the function has the day mont and year passed to it as parameters and then outputs which day of the week it falls on.
Ammend the zeller function so the user may input the month number in conventional format.
the line in main that calls zeller should now be changed to a comment for use later.
use a switch statement in a seperate function called no_in_month, to return and output the number of days in any month.call the no_in_month function from main,the output should be in main.
change no_in month so now there are two parameters passed to it, the month and the year. amend this function so that leap years may be input. a leap year occurs if the year is evenly divisible by 4.
use the call from main to the zeller function(made a comment in step 5) to output which day of the week any month begins
the outputs described in stepds 7 and 8(the day the month starts and the number of days in the month) may now be used as parameters to be passed to the output_month function.
tidy up the program so that a year and month only are inputs and the appropriate calendar is output.
#include "stdafx.h"
#include <iostream>
using namespace std;
#include <iomanip>
void output_month(int start, int total) {
cout << " S M T W T F S" << endl;
cout << setw(5 * start ) << "";
You have already made a function to output the month. The next step would be to make another function that takes three integer parameters and returns an int. E.g. this is a prototype for your zeller function:
int zeller(int day, int month, int year);
The function would need to calculate the decade and century (using the integer tips given), and then simply return the result of that formula you're given.
Before calling this function from main, you need to get the day, month and year from the keyboard input using cin in exactly the same way you've done for the other integers already. After that, simply call the zeller function using these three integers.
Once you've got that far, post your code and we'll go from there...
Comments:
1. Please use the code tags when posting code. Find them on the right hand side (they look like '<>').
2. The 'zeller' function should have an int return type, because you're returning an integer from it!
3. Lots of your cin/cout lines are missing semicolons at the end of the line. The compiler will whinge at this...
4. You have to declare what 'day', 'month' and 'year' are (hint: they're all ints) BEFORE you use them. This looks like:
int day, month, year;
5. When calling your function from main, you don't have to pass the type. The compiler ensures a match between the types given in the function prototype to the pre-declared types of the variables passed.
6. You have to do something with the result of the zeller call, or else it will be lost!
After I fixed all the above points (which I won't post because you should do it), the program seemed to work ok :). That should motivate you to finish...
the zeller function wont work?
I tried to do what you asked but it still wont work, it compiles but it says the variable month, day and year are not initialized.
any help please?
#include "stdafx.h"
#include <iostream>
using namespace std;
#include <iomanip>
void output_month(int start, int total) {
cout << " S M T W T F S" << endl;
cout << setw(5 * start ) << "";
Ok, you need to be smarter. First, DON'T double post things. It will make us angry. Secondly, use the code tags like I told you above.
The problem is that you're not passing the day/month/year variables from MAIN into your zeller function. You need to change your zeller function to accept three integer parameters, and then call zeller(day, month, year) from main.
You must understand that if you declare variables called 'day', 'month' and 'year' in main, and the variables 'day', 'month' and 'year' locally in zeller, THEY ARE NOT THE SAME VARIABLES!