Return to Snippet

Revision: 52395
at October 23, 2011 03:29 by javageget


Updated Code
// Effy-20111021.cpp : Defines the entry point for the console application.
// This program written using Visual C++ 2010 bish!!

// printf(); Reference: http://www.cplusplus.com/reference/clibrary/cstdio/printf/
// scanf(); Reference: http://www.cplusplus.com/reference/clibrary/cstdio/scanf/
// Modulo splitting digits: http://www.daniweb.com/software-development/c/threads/310740
/*********************************************************************************
d1 = r % 10 * Thinking from right to left, we first store d1 *
r /= 10 * Now we drop the last digit of r, as we don't need it anymore *

* By the time we've got all of d1, d10 and d100, r will be equal to r / 1000 *
**********************************************************************************/

//#include <stdio.h>		// Include standard libs instead of stdafx.h (the windows shit)
#include "stdafx.h"		// Windows precompiled library and shits.
#include <iostream>		// Include standard C++ Libs.
//#include <iomanip>		// Reference on setw + setfill http://msdn.microsoft.com/en-us/library/daeb650d(VS.80).aspx

using namespace std;

int _tmain()
{
	// We gonna use some variables.
	int usertime = 0;
	int hours = 0;
	int minutes = 0;
	
	printf ("Enter time in 24hrs format: ");
	//scanf_s ("%d", &usertime);
	cin >> usertime;
	
	//newline setting
	printf("\n\n");

	// Splitting minutes and hours using modulo operation.
	minutes = usertime % 100;
	hours = usertime / 100;

	// Validating Minutes first. (There's workaround for it actually)
	if (minutes >= 0 && minutes < 60) {

		// 12 AM Flag
		if (hours == 0 || hours == 24){
			printf ("24hrs time is: %d.\n", usertime);
			printf ("12hrs time is: 12:%02d AM.\n", minutes);
			
			// 1 AM to 11AM
		} else if (hours >= 1 && hours <= 11) {
			printf ("24hrs time is: %04d.\n", usertime);
			printf ("12hrs time is: %02d:%02d AM.\n", hours, minutes);

		// 12PM to 11PM (On-fly conversion. woohoo
		} else if (hours >= 12 && hours <= 23) {
			printf ("24hrs time is: %04d.\n", usertime);
			printf ("12hrs time is: %02d:%02d PM.\n", hours%12 , minutes);
		} else {
			printf ("Invalid time!");
		}
	} else {
		printf ("Please reconsider your minute value!\n\n");
	}

	system("Pause");
	return 0;
}

Revision: 52394
at October 21, 2011 17:35 by javageget


Initial Code
// Effy-20111021.cpp : Defines the entry point for the console application.
// This program written using Visual C++ 2010 bish!!

// printf(); Reference: http://www.cplusplus.com/reference/clibrary/cstdio/printf/
// scanf(); Reference: http://www.cplusplus.com/reference/clibrary/cstdio/scanf/
// Modulo splitting digits: http://www.daniweb.com/software-development/c/threads/310740
/*********************************************************************************
d1 = r % 10 * Thinking from right to left, we first store d1 *
r /= 10 * Now we drop the last digit of r, as we don't need it anymore *

* By the time we've got all of d1, d10 and d100, r will be equal to r / 1000 *
**********************************************************************************/

//#include <stdio.h>		// Include standard libs instead of stdafx.h (the windows shit)
#include "stdafx.h"		// Windows precompiled library and shits.
#include <iostream>		// Include standard C++ Libs.
//#include <iomanip>		// Reference on setw + setfill http://msdn.microsoft.com/en-us/library/daeb650d(VS.80).aspx

//using namespace std;

int _tmain()
{
	// We gonna use some variables.
	int usertime = 0;
	int hours = 0;
	int minutes = 0;
	
	printf ("Enter time in 24hrs format: ");
	scanf_s ("%d", &usertime);
	
	//newline setting
	printf("\n\n");

	// Splitting minutes and hours using modulo operation.
	minutes = usertime % 100;
	hours = usertime / 100;

	// Validating Minutes first. (There's workaround for it actually)
	if (minutes >= 0 && minutes < 60) {

		// 12 AM Flag
		if (hours == 0 || hours == 24){
			printf ("24hrs time is: %d.\n", usertime);
			printf ("12hrs time is: 12:%d AM.\n", minutes);
			
			// 1 AM to 11AM
		} else if (hours >= 1 && hours <= 11) {
			printf ("24hrs time is: %d.\n", usertime);
			printf ("12hrs time is: %d:%d AM.\n", hours, minutes);

		// 12PM to 11PM (On-fly conversion. woohoo
		} else if (hours >= 12 && hours <= 23) {
			printf ("24hrs time is: %d.\n", usertime);
			printf ("12hrs time is: %d:%d PM.\n", hours%12 , minutes);
		} else {
			printf ("Invalid time!");
		}
	} else {
		printf ("Please reconsider your minute value!\n\n");
	}

	system("Pause");
	return 0;
}

Initial URL


Initial Description
dok rok cetong boh

Initial Title
24hrs Time Converter for Effy~

Initial Tags


Initial Language
C++