my code stock.com

You can just type in a date… Output is day of this date.

Snippet options

Download: Download snippet as date.cpp.
Copy snippet: For this you need a free my code stock.com account.
Embed code : You will find the embed code for this snippet at the end of the page, if you want to embed it into a website or a blog!

#include <iostream>
using namespace std;

int main() {

	int f, k, m, y, D, C, den;



	cout << "Enter date";
	cin >> k;
	cin >> m;
	cin >> y;

		switch (m) {
		case 1:
			m = 11;
			break;
		case 2:
			m = 12;
			break;
		case 3:
			m = 1;
			break;
		case 4:
			m = 2;
			break;
		case 5:
			m = 3;
			break;
		case 6:
			m = 4;
			break;
		case 7:
			m = 5;
			break;
		case 8:
			m = 6;
			break;
		case 9:
			m = 7;
			break;
		case 10:
			m = 8;
			break;
		case 11:
			m = 9;
			break;
		case 12:
			m = 10;
			break;
		default:
			cout << "Wrong choice.\n";
			break;
		} 

	C = (y / 100);
	D = y % 100;

	if (m = 1)
		D--;
	else if (m = 2)
		D--;


	f = k + ((13 + m - 1) / 5) + D + (D / 4) + (C / 4) - 2 * C;
	den = f % 7;

/*	switch (den) {
	case 0:
		cout << "Nedele\n";
		break;
	case 1:
		cout << "Pondeli\n";
		break;
	case 2:
		cout << "Utery\n";
		break;
	case 3:
		cout << "Streda\n";
		break;
	case 4:
		cout << "Ctvrtek\n";
		break;
	case 5:
		cout << "Patek\n";
		break;
	case 6:
		cout << "Sobota\n";
		break;
	}*/
	//thus is part of program, but turned off, because i need to explore the mistake
	cout << "k=" << k << endl << "m=" << m << endl << "C=" << C << endl << "D=" << D << endl << "f=" << f << endl << "den=" << den << endl;
//this can show me the mistake. The mistake is in mounth, but i don't know where...
	return 0;
}

Create a free my code stock.com account now.

my code stok.com is a free service, which allows you to save and manage code snippes of any kind and programming language. We provide many advantages for your daily work with code-snippets, also for your teamwork. Give it a try!

Find out more and register now

You can customize the height of iFrame-Codes as needed! You can find more infos in our API Reference for iframe Embeds.