showing the output of an integer as a 24 hour number

I was wondering if anyone could help me get the values represented by (int the_hour) to show up with a preceeding 0. So it would look like this: 00, 01, 02, 10, 20, 23. Any help would be much appreciated.

1
2
3
4
5
6
7
8
9
10
11
void GetTempratures(int Tempratures[], int NumTempratures)
{	
	//Declerations
	int i = 0;
	int the_hour = 0;

	//Input data to array
	for (i = 0; i < NumTempratures; i++)
	                cout <<"Please Enter a Temprature for " <<the_hour++ <<":00 " &&
		cin >> setw(4) >> Tempratures[i];
}
Last edited on
The output looks like this

Please Enter a Temprature for 0:00 1
Please Enter a Temprature for 1:00 2
Please Enter a Temprature for 2:00 3
Please Enter a Temprature for 3:00 4
Please Enter a Temprature for 4:00 5

I want the output to look like this

Please Enter a Temprature for 00:00 1
Please Enter a Temprature for 01:00 2
Please enter a temprature for 10:00 3 etc.


the simplest solution is
1
2
3
if ( x < 10 )
    cout << '0';
cout << x;
Topic archived. No new replies allowed.