How do I set up a time function?

So I started off with a simple project below. Basically I set it up so that when it was the weekends it would say "Its The Weekends!". However I'm a beginer at programming, and so I had to make it so I manually had to tell the program what day it way. I was hoping I could make it so that the program automatically grabs the time from the OS, and calculated if its the weekends or Weekdays.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
// WeekendApp.cpp : Defines the entry point for the console application.
//

#include "stdafx.h"


int _tmain(int argc, _TCHAR* argv[])
{
	return 0;
}

#include <iostream> 
#include <ctime> 
#include <Windows.h>
#include <stdio.h>

int main() 

{ 

	enum Days { Monday, Tuesday, Wednesday, 
		Thursday, Friday, Saturday, Sunday }; 

		
	int tmain() 
      {
          SYSTEMTIME st;
          GetSystemTime(&st);
          printf("Year:%d\nMonth:%d\nDate:%d\nHour:%d\nMin:%d\nSecond:% d\n" ,st.wYear,st.wMonth,st.wDay,st.wHour,st.wMinute,st.wSecond);
      }

	 

	if (today== Saturday || today==Sunday); 
		std::cout << "\nIts the weekends!\n";

	else 

		std::cout << "\nBack to work!\n"; 


	system("PAUSE"); 

	return 0; 

} 


This is what I got from someone online, but idk how to implement it or fix the errors visual studios gives me.


1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
// DaysOfTheWeek.cpp : Defines the entry point for the console application.
//

#include "stdafx.h"


int _tmain(int argc, _TCHAR* argv[])
{
	return 0;
}



#include < iostream >
#include < cmath >

using namespace std;

int main ()

{
	float dwi;		// Input data for day of week year began
	float dyi;		// Input data for the day of the year
	double dayOfYear;	// Output data for day of year
	bool numbersAreOK;	// True if data is within the range of 1-366

	
	// Prompt for what day of the week the year begins on
	cout << "To represent what day the year began on, please enter a whole number from 0-6." " " "0 representing Sunday, 6 representing Saturday. " << endl;
	cin >> dwi;

	// Prompt for the day of the year
	cout <<  " Please enter a whole number from 1-366 to represent the day of the year you wish to display." << endl;
	cin >> dyi;

	// Test Data
	if ( dwi < 0 || dwi > 6)  
		numbersAreOK = false;
		cout << "Invalid data, please try again." << endl;

	if ( dyi < 1 || dyi > 366)
		numbersAreOK = false;
		cout << "Invalid Data, Please try again." << endl;

	if ( numbersAreOK = true)
	{

	// Calculate day of year
	double dayOfYear = (dwi + dyi-1)%7;

	// Print Day of Year
	if (dayOfYear == 0)
		cout << "Sunday" << endl;

		else if (dayOfYear ==  1)
			cout << "Monday" << endl;

		else if (dayOfYear ==  2)
			cout << "Tuesday" << endl;

		else if (dayOfYear == 3)
			cout << "Wednesday" << endl;

		else if (dayOfYear ==  4)
			cout << "Thursday" << endl;

		else if (dayOfYear ==  5)
			cout << "Friday" << endl;

		else if (dayOfYear == 6)
			cout << "Saturday" << endl;
	}
		cin.get();
		cin.get();

	return 0;
}
Last edited on
Topic archived. No new replies allowed.