Hello! I am working on my project..my code looks fine but I always get a wrong output. For example: I enter 11 for hour, 05 for minutes. The output should be display 11:05...but anyway it shows me 11:5
The zero is gone?? Is there anything i'm missing?? Please let me know how to fix this issue...thanks in advance

#include "stdafx.h"
#include <iostream>

using namespace std;

int _tmain(int argc, _TCHAR* argv[])
{
	int hour;
	int minutes;

	cout << " Enter the time.\n ";
	cin >> hour;
	cin >> minutes;

	cout << hour << ":" << minutes << endl;
	
	return 0;
}

you have to use setw(2) and setfill('0') in the cout statement cout << setw(2) << setfill('0') << minutes << '\n';

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.