Help a noob out.

Hello, not long ago I started learning c++ (no programming experiance before that) I am starting off slow and I would like your help.

This is my task:

Clocks time is in hours, minutes and seconds.
Increase the time by one second. Show the initial time and the time after one second.

I know I need to write in with loops, but I am a noob and I seek help.

Why would you need a loop?
You need to increase the time only once.
You are right. I did the code

#include "iostream"
#include "cstdlib"

using namespace std;

int main()
{
int h, m, s;
cout <<" Dial hours, minutes and seconds ";
cin >> h;
cin >> m;
cin >> s;

cout << " Initial time " << h << " hours " << m <<" minutes " << s << " seconds" << endl;

s = s+1;

cout << " Time " << h << " hours " << m <<" minutes " << s << " seconds" << endl;

system("pause");
return 0;
}

Is it possible to imput your computers time and then add 1 second. If yes, then how ?
Please put your code inside code blocks ([code]). @Thomas1965 is right. No need for loop(s). But what you actually need is a couple of if statements. Because if incrementing the second makes it 60 then it is obvious that you need to increment the minute(s) by 1 and reduce the second by 60. Don't forget to do the same to the hour(s) considering the fact that 60 minutes equals 1 hour.
Last edited on
Thanks @Xenophobe gonna try to write it.
Is it possible to input your computers time and then add 1 second. If yes, then how ?


There are C++ library functions you can use for time stuff.


http://www.cplusplus.com/reference/ctime/time/

https://www.tutorialspoint.com/cplusplus/cpp_date_time.htm

http://en.cppreference.com/w/cpp/chrono/c/time

https://www.tutorialcup.com/cplusplus/date-time.htm
Topic archived. No new replies allowed.