Broken clock problem..

Hello I am trying to solve a very simple program but i dont know why my code isn't correct at all test data.

The Problem: The Clock of Tom is broken and its show the half time than the correct time. If it pass 30 seconds the clock shows only 15 seconds.
00<=HH<=99, 00<=MM<=59, 00<=SS<=59
Write a program that solve this problem:
INPUT: 12:44:03
OUTPUT: 25:28:06

My Code which is correct at 6/10 test data.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
#include<iostream>  
#include<fstream>  
using namespace std;  
  
int main()  
{  
	ifstream input("time.txt", ios::in);  
	ofstream output("time.txt", ios::out);  
	int hours, minutes, seconds;  
  
	char colon;  
	input >> hours >> colon >> minutes >> colon >> seconds;  
  
	input.close();  
	int n_sec, n_min, n_hour;    
	n_sec = seconds * 2;
        n_min = 0;
  
	if (n_sec > 59)  
	{     
    	n_min = n_sec/60;  
    	n_sec = n_sec - (60*n_min);  
	}  
  
	n_min = n_min + (minutes * 2);  
	if (new_min>59)  
	{  
    	n_hour = n_min/60;  
    	n_min = n_min - (n_hour*60);      
	}  
  
	n_hour = n_hour + (hours * 2);  
	if (n_hour > 99)  
	{  
		n_hour = 99;    
   }  
	output << n_hour << ":" << n_min << ":" << n_sec << endl;  
}
Topic archived. No new replies allowed.