• Forum
  • Lounge
  • Need help to overcome compile time Const

 
Need help to overcome compile time Constant requirement.


//This is working fine if value of addMinutes=30(Hard codded , Declared as [const int addMinutes=30], but i want the user to enter this minutes, any solution other than constructor initialization, Please help.)

string MyFuture::calculateTime(){
int addMinutes;
cout<<"Please enter delay time ";
cin>>addMinutes;

using std::chrono::system_clock;

std::chrono::duration<int,std::ratio<addMinutes*60> > futureTime(1);

system_clock::time_point today = system_clock::now();
system_clock::time_point tomorrow = today + futureTime;

std::time_t tt;

tt = system_clock::to_time_t ( today );
std::cout << "Processed at: " << ctime(&tt);

tt = system_clock::to_time_t ( tomorrow );
std::cout << "Future Time: " << ctime(&tt);
struct tm tstruct;
char buf[80];
tstruct = *localtime(&tt);

strftime(buf, sizeof(buf), "NEW DATE: %Y-%m-%d and NEW TIME:%X", &tstruct);

return buf;
}
Topic archived. No new replies allowed.