C++ program to add seconds to the time
In this program, we are going to learn adding seconds to the time.
Consider the program:
#include <iostream> using namespace std; void addSecond(int *hh, int *mm,int *ss) { if( *ss == 59 ) { if( *mm == 59 ) { cout<<endl<<"hh: "<<*hh<<" mm: "<<*mm<<" ss:"<<*ss<<endl; if(*hh == 23) *hh=0; else (*hh)++; *mm=0; *ss=0; } else { (*mm)++; *ss=0; } } else { (*ss)++; } } int main() { int hh=23,mm=59,ss=59; cout<<"Time before adding second(s): "<<hh<<":"<<mm<<":"<<ss<<endl; addSecond(&hh, &mm, &ss); cout<<"Time After adding second(s) : "<<hh<<":"<<mm<<":"<<ss<<endl; return 0; }
Output
Time before adding second(s): 23:59:59 hh: 23 mm: 59 ss:59 Time After adding second(s) : 0:0:0
In above example, we have added one second to 23:59:59 in 24 hours clock. Thus, the output is 0:0:0, it is in next day.
total answers (1)
start bookmarking useful questions and collections and save it into your own study-lists, login now to start creating your own collections.
In this program, we are going to learn adding seconds to the time.
Consider the program:
Output
In above example, we have added one second to 23:59:59 in 24 hours clock. Thus, the output is 0:0:0, it is in next day.
need an explanation for this answer? contact us directly to get an explanation for this answer