Originally Posted by
Elysia
You need to indent properly. Then you must make sure main returns int (you haven't specified a return type which is illegal).
And a counting clock may not be a very good program. The problem is that you cannot guarantee that it will go up by one exactly every second. You have to deal with some error margin, which might not be as intuitive to a newbie.
I think there are far worse things wrong with this code other than just imprecision, no?
Code:
#include <stdio.h> Use <cstdio>, this one is deprecated.
#include <fstream>You don't use anything from this header in the code, get rid of it.
#include <iostream>
#include <cstring>You don't use anything from this header in the code, get rid of it.
using namespace std;
main(){ As Elysia pointed out this is wrong, make it "int main()"
int hour;
int minute;
int second;
cout<<"Please enter the current hour...\n";
cin >> hour;
cin.get();
cout<<"Thanks, now please enter the minute\n";
cin>>minute;
cin.get();
cout<<"Setting time...\n";
cin.ignore();
second = + 1; What is this line supposed to do? Either you need to remove the plus, or make the "=+" a "+=" instead, but since the variable is not initialized this would be undefined behavior
if (second > 59) {
minute + 1;}
if (minute > 59) {
hour + 1;}
if (hour > 24) {
hour = 0;
minute = 0;
second = 0;
}
if (hour > 0 && minute > 0)
{cout<<"The time is "<<hour<<":"<<minute<<":"<<second<<" tick tock tick tock!\n";
}
}
The lines in red don't do anything, you calculate a value but you never store i anywhere, either make "minute +1" into "minute++" or "minute +=1"
Most of these you would have caught if you turned on compiler warnings :-)