Pages

Monday, March 2, 2009

My First Serious Program

I've been programming in C for about a month. It's only by now I have started serious programming. This is my first serious program in C. It's a simple calculator. I'm waiting to upgrade it in the days to come as my C knowledge improves. Till then, enjoy it!:D
#include "stdio.h"
#include "stdlib.h"
#define Y 1
int main()
{
char num[5],name[10],ch;
int dst,i;
double one,two,add,sub,multi,div;
printf("***THIS IS THE BASIC CALCULATOR PROGRAM CREATED BY CHAMMA***\n");
printf("All Rights Reserved ® Chamitha Rathnayake\n");
printf("Enter the user's name:");
gets(name);
for(i=0;i=Y;i++)
{
printf("Specify your intended #1:");
gets(num);
one=atof(num);
printf("Specify your intended #2:");
gets(num);
two=atof(num);
printf("If you want to perform addition only, enter #1\n");
printf("If you want to perform substraction only, enter #2\n");
printf("If you want to perform multiplication only, enter #3\n");
printf("If you want to perform division only, enter #4\n");
printf("If you want to perform all-in-one, enter #5\n");
gets(num);
dst=atoi(num);
printf("Press Enter to continue to the result...\n");
getchar();
printf("%s's calculator derives the following result:\n",name);
if(dst==1)
{
add=one+two;
printf("Addition of the numbers you entered is:%lf\n",add);
}
if(dst==2)
{
sub=one-two;
printf("Substraction of the numbers you entered is:%lf\n",sub);
}
if(dst==3)
{
multi=one*two;
printf("Multiplication of the numbers you entered is:%lf\n",multi);
}
if(dst==4)
{
div=one/two;
printf("Division of the numbers you entered is:%lf\n",div);
}
if(dst==5)
{
add=one+two;
printf("Addition of the numbers you entered is:%lf\n",add);
sub=one-two;
printf("Substraction of the numbers you entered is:%lf\n",sub);
multi=one*two;
printf("Multiplication of the numbers you entered is:%lf\n",multi);
div=one/two;
printf("Division of the numbers you entered is:%lf\n",div);
}
printf("That is the end of a silly program.\n");
printf("One more thing! Press Enter to continue...\n");
getchar();
printf("I love you %s!\n",name);
getchar();
printf("Press Enter to go to the begining\n");
printf("Press 'X' and then 'Enter' to exit\n");
ch=getchar();
fflush(stdin);
if(ch=='X' or ch=='x')
{
break;
}
}
printf("Thanks for using this calculator\n");
printf("Promote FOSS,the Free and Open Source Software\n");
printf("Bye!\n");
getchar();
return(0);
}

1 comments:

Chamila said...

meka nam echchara amaru nane.

Post a Comment

මේ ලිපිය ගැන ඔබට හිතෙන්නේ මොකක්ද? ගල්, මුල්, මල් ඕන දේකට ඉඩ...
සිංහලෙන් යතුරු කරන්නට යුනිකේත එසැණින් පරිවර්තකය භාවිතා කරන්න පුළුවන්.