Love
November 28th, 2010In reality, there is no permanent love. As time passess your feelings to someones changes. As much as possible never give 100% love because if she/he doesn’t love you will not hurt too much. Like this quote - “A sad thing in life is that sometimes you meet someone who means a lot to you only to find out in the end that it was never bound to be and you just have to let go.”
We must learn to love, to be hurt and let go…
Turbo C Sample Input Validation
October 19th, 2010Input validation in turbo c is one of the problem by many programmers. If the input is not properly filtered by the program, it can ruined the entire program. Here is my sample program.
#include <math.h>
#include <stdio.h>
#include <conio.h>
#include <string.h>
#include <stdlib.h>void main_menu(void);
void sub_menu(void);
void area_of_circle(void);
void area_of_triangle(void);
void area_of_square(void);
void input_validation(char tempo[6], int mem_pt);
void save_pt(int memo);void save_pt(int memo)
{
switch (memo)
{
case 1: area_of_circle();
case 2: area_of_triangle();
case 3: area_of_square();
}
}void input_validation(char tempo[6], int mem_pt)
{
int deci_ptr=0,i=0;
while (tempo[i]!=’\n’)
{
if (tempo[i]==’.'&&deci_ptr==1)
{
printf(”\nToo much decimal point!!!”);
getch();
save_pt(mem_pt);
}
if (tempo[i]<’0′||tempo[i]>’9′)
{
printf(”\nPlease enter a number!!!”);
getch();
save_pt(mem_pt);
}
if (strlen(tempo)==1&&tempo[i]==’.')
{
printf(”\nPlease enter a number!!!”);
getch();
save_pt(mem_pt);
}
if (tempo[i]==’.') deci_ptr=1;i++;
}
}void main_menu(void)
{
char c;
clrscr();
printf(”Main Menu:\n\n”);
printf(”[a] Area of Circle\n”);
printf(”[b] Area of Triangle\n”);
printf(”[c] Area of Square\n”);
printf(”Select: “);
c=getche();
switch (c)
{
case ‘a’: area_of_circle();
case ‘A’: area_of_circle();
case ‘b’: area_of_triangle();
case ‘B’: area_of_triangle();
case ‘c’: area_of_square();
case ‘C’: area_of_square();
default: printf(”\nPlease select from the menu!”);getch();main_menu();
}
}void sub_menu(void)
{
char c;
printf(”\n\nGoto Main Menu: [Y/N]: “);
c=getche();
switch (c)
{
case ‘y’: main_menu();
case ‘Y’: main_menu();
case ‘n’: printf(”\nGood bye!!!”);getch();exit(0);
case ‘N’: printf(”\nGood bye!!!”);getch();exit(0);
default: printf(”\nError!!!”);getch();sub_menu();
}
}void area_of_circle(void)
{
char number[6];
float area,radius;
clrscr();
printf(”Area of Circle:\n\n”);
printf(”Enter the radius of circle: “);
fgets(number,6,stdin);
input_validation(number,1);
radius=atof(number);
printf(”\nThe area of the circle is %f”,radius*radius*M_PI);
getch();
sub_menu();
}void area_of_triangle(void)
{
char number[6];
float area,base,height;
clrscr();
printf(”Area of Triangle:\n\n”);
printf(”Enter base: “);
fgets(number,6,stdin);
input_validation(number,2);
base=atof(number);
printf(”\nEnter height: “);
fgets(number,6,stdin);
input_validation(number,2);
height=atof(number);
printf(”\nThe area of the triangle is %f”,base*height/2);
getch();
sub_menu();
}void area_of_square(void)
{
char number[6];
float area,height;
clrscr();
printf(”Area of the Square:\n\n”);
printf(”Enter the height: “);
fgets(number,6,stdin);
input_validation(number,3);
height=atof(number);
printf(”\nThe area of the square is %f”,height*height);
getch();
sub_menu();
}void main(void)
{
main_menu();
}
Happy programming. ![]()
Marina Bay
October 9th, 2010Trip to Sentosa
October 9th, 2010Julian Beever at VivoCity
October 9th, 2010Life in Singapore
September 6th, 2010First week studying autocad
April 10th, 2010The Rubik Cube
March 26th, 2010The Rubik Cube is one of my favorite toy. Invented by ErnÅ‘ Rubik of Budapest, Hungary. Rubik cube comes in 2×2, 3×3, 4×4, 5×5, 6×6 and 7×7. For more information about this cube visit rubiks.
Solving the Rubik cube (3×3) is quite hard for first timer. To solve the cube easily you must first start to the bottom layer, then middle layer and lastly to the top layer. Check the youcandothecube for some information in solving the Rubik’s cube.































































