Witam!
Mam otóż taki problem: Error 1 error C4996: 'localtime': This function or variable may be unsafe. Consider using localtime_s instead. To disable deprecation, use _CRT_SECURE_NO_WARNINGS. See online help for details. d:\l2p\consoleapplication1\consoleapplication1\consoleapplication1.cpp 68 1 ConsoleApplication1
Czyli jednym słowem, nie pobiera mi aktualnego czasu...
Kod:
// ConsoleApplication1.cpp : Defines the entry point for the console application.
//
#include "stdafx.h"
#include <iostream>
#include <conio.h>
#include <ctime>
#include <string>
#include <cmath>
#include <time.h>
// Biorhytm
// enumerated type, specifying the type of biorhytm
// typ wyliczeniowy, określający rodzaj biorytmu
enum BIORHYTM {
BIO_PHYSICAL = 23,
BIO_EMOTIONAL = 28,
BIO_INTELECTUAL = 33
};
// PI
const double PI = 3.1415926538;
// ---------------------------------------------------
// enumerated feature a type of biorhytm
double Biorytm(double fDays, BIORHYTM Cycle){
return 100 * sin((2 * PI / Cycle) * fDays);
}
// main function
void main(){
/* three structures that store data of brith culprit
the current time and the difference between them */
tm DateOfBirth = { 0, 0, 0, 0, 0, 0, 0, 0, 0 };
tm CurrentlyTime = { 0, 0, 0, 0, 0, 0, 0, 0, 0 };
tm TimeDifference = { 0, 0, 0, 0, 0, 0, 0, 0, 0 };
// asking a user for a date of birth
std::cout << "Podaj date urodzenia" << std::endl;
// day
std::cout << "-dzien: ";
std::cin >> DateOfBirth.tm_mday;
// month
// we have to subtract 1 becouse user give him 1..12
std::cout << "-miesiac: ";
std::cin >> DateOfBirth.tm_mon;
DateOfBirth.tm_mon--;
// year
// now we have to substrart 1990...
std::cout << "-rok: ";
std::cin >> DateOfBirth.tm_year;
DateOfBirth.tm_year--;
// we calculate the number of days lived
// we charge current time in the form of structures
time_t tTime = time(NULL);
CurrentlyTime = *localtime(&tTime);
TimeDifference.tm_mday = CurrentlyTime.tm_mday - DateOfBirth.tm_mday;
TimeDifference.tm_mon = CurrentlyTime.tm_mon - DateOfBirth.tm_mon;
TimeDifference.tm_year = CurrentlyTime.tm_year - DateOfBirth.tm_year;
// we compute it to days
double fLivedDays = TimeDifference.tm_year * 365.25
+ TimeDifference.tm_mon * 30.4374
+ TimeDifference.tm_mday;
// we comute biorhytm and show it
std::cout << std::endl;
std::cout << "Twoj biorytm:" << std::endl;
std::cout << "- fizyczny: " << Biorytm(fLivedDays, BIO_PHYSICAL) << std::endl;
std::cout << "- emocjonalny: " << Biorytm(fLivedDays, BIO_EMOTIONAL) << std::endl;
std::cout << "- intelektualny: " << Biorytm(fLivedDays, BIO_INTELECTUAL);
// waiting for any key
_getch();
}