my output keeps putting out monday for everything need help with this, kinda confused on what im dooing

#include <iostream>
#include <iomanip>
using namespace std; 
void displayTitle();
int getMonth(int month);
int getDay(int day);
int getYear(int year);
int CalcDayofWeek(int month, int day, int year);
void displayDay(int G);
int main()
{
	//declare variables
	int month, 
	        day, 
	       year;
	int M, //month number
		K, //day of the month
		C, //century year
		D, //year number
		G;
		
	//input
	
	displayTitle();
	getMonth(month);
	getDay(day);
	getYear(year);

	//process
	CalcDayofWeek(month, day, year);
	//output
	displayDay(G);

	system("pause");
	return 0;
}
void displayTitle()
	{
	cout<< setw(30) << "Zeller's Algorithm\n";
	cout<<endl;
	}
int getMonth(int month)
	{
	cout<< setw(20) << "Enter the month <or 0 to exit>";
	cin>>month;
	cout<<endl;
	return month;
	}
int getDay(int day)
	{
	cout<< setw(20) << "Enter the day                 ";
	cin>>day;
	cout<<endl;
	return day;
	}
int getYear(int year)
	{
	cout<< setw(20) << "Enter the year                ";
	cin>>year;
	cout<<endl;
	return year;
	}
int CalcDayofWeek(int month, int day, int year)
    {
    int M = month;
	int K = day;
    int C = year / 100;
    int D = year % 100;
	int G;
	G = static_cast<double> )2.6 * M - 0.2) + K + D + (D/4) + (C/4) - 2 * C;
		if (G < 0)
			G = G + 7;
		return G;
    }
	void displayDay(int G)
	{
    switch (G)
    {
    case 0: cout << "Sunday" << endl; break;
    case 1: cout << "Monday" << endl; break;
    case 2: cout << "Tuesday" << endl; break;
    case 3: cout << "Wednesday" << endl; break;
    case 4: cout << "Thursday" << endl; break;
    case 5: cout << "Friday" << endl; break;
    case 6: cout << "Saturday" << endl; break;
    }
	}

Recommended Answers

All 3 Replies

>>(D/4) + (C/4)
This is doing integer arithmetic, meaning all decimals are discarded leaving only the integer portion. try casing to double to see if it fixed your problem -- I don't know whether it will or not ( (double)D / 4.0) + ( (double)C / 4.0)

i tried that but it still just outputs mon for everything i input

You have functions that return values, yet you don't capture or use those in main( ). You are probably always computing the day that the random value in memory that G points to equates to.

Garbage In, Garbage Out

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.