Im programming a watch that takes the hoursminutesseconds an

I\'m programming a watch that takes the hours,minutes,seconds and the day for the date in C++ . I have a setTime(12,30,25) to set the parameters manually .

I need help implementing the watch using the ctime library and display it on the console screen updating as the time changes. Can someone help me?

Solution

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

#include<conio.h>
#include <time.h>
#include <unistd.h>

//To setTime by user
void setTime(struct tm &timeinfo)
{
int hh, min ,sec;
printf(\"enter HH,MM,SS\");
scanf(\"%d%d%d\",&hh,&min,&sec);
  
timeinfo.tm_hour = hh;
timeinfo.tm_min = min;
timeinfo.tm_sec = sec;

}

int main()
{
struct tm timeinfo;
int day;
std::cout<<\"enter day\";
std::cin>>day;
timeinfo.tm_mday = day;
setTime(timeinfo);

while(1)
{
timeinfo.tm_sec = timeinfo.tm_sec+1;
mktime(&timeinfo);

//clrscr();   

std::cout<<<< \"\\33[2J\";

printf(\"%s\",asctime(&timeinfo));
sleep(1000);

}
}

I\'m programming a watch that takes the hours,minutes,seconds and the day for the date in C++ . I have a setTime(12,30,25) to set the parameters manually . I ne

Get Help Now

Submit a Take Down Notice

Tutor
Tutor: Dr Jack
Most rated tutor on our site