Intializing error

error hour is not intialized but i intialized hour to zero

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
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
#include<iostream>
#include<conio.h>
#include<stdexcept>
using namespace std;
class Times
{
private:
	int hours;
	int minutes;
	int seconds;
public:
	Times()
	{hours=0;minutes=0;
	seconds=0;}
	Times(int h ,int m , int s) : hours(h), minutes(m),seconds(s){}
	void setTimes(int h ,int m ,int s)
	{
		if ((h>0&&h<=24) && (m>0&&m<=60 ) && (s>0&&s<=60))
		{
			hours=h;minutes=m;seconds=s;
		}
	
	}
	void printuniversal()
	{
		if ((hours>0&&hours<=24) && (minutes>0&&minutes<=60 ) && (seconds>0&&seconds<=60))
			cout<<hours<<":"<<minutes<<":"<<seconds<<endl;
		
	}
	void printprime()
	{
		if (hours>12 && hours<=24)
			int hours=hours-12;
	
	cout<<hours<<":"<<minutes<<":"<<seconds<<endl;
	}
};




#include<stdexcept>
#include"TIME_H.h"
#include<conio.h>
#include <iostream>
using namespace std;
int main () 
{
	Times t1;
	t1.printuniversal();
	
	t1.setTimes(23,12,12);
	t1.printprime();
	t1.printuniversal();
}
 
At line 33 you declared a new variable:
 
    int hours=hours-12;
Topic archived. No new replies allowed.