i have broke my code up into 4 files so that i can use them in other programs if needed.
MAIN.c
#include<stdio.h>
#include<stdlib.h>
#include<math.h>
#include<windows.h>
#include<time.h>
#include<dos.h>
#include<unistd.h>
//prototype functions FAILSAFE
void DRAWCOLLUMNS_F(void);
int HYPOTENUSE_F(void);
int HYPOTENUSER_F(void);
float BASIC_CALCULATOR_F(void);
void main()
{
//char for choice selection
char choice,menuopt;
START:
DRAWCOLLUMNS_F();//draw box
_flushall();
choice=getchar();//ask for users choice
switch(choice)
{
case'1':
clearscreen();
_flushall();
HYPOTENUSE_F();
goto EOS;
case '2':
clearscreen();
_flushall();
HYPOTENUSER_F();
goto EOS;
case '3':
clearscreen();
_flushall();
BASIC_CALCULATOR_F();
goto EOS;
case'x':
goto END;
default:
clearscreen();
printf("Sorry that is an invalid selection\n");
}
EOS:
printf("would you like to return to the main menu?(y for yes any other key for no).\n");
_flushall();
menuopt=getchar();
if(menuopt=='y'||menuopt=='Y')
{
clearscreen();
goto START;
}
else
goto END;
END:
return 0;
}
void DRAWCOLLUMNS_F(void)
{
//ints for drawing the border
int UL=201,UR=187,F=205,UPT=203,DWNT=202,DL=200,DR=188,VERT=186,LT=204,RT=185;
//draw collumns
printf("%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c\n",UL,F,F,F,F,F,F\
,F,F,F,F,F,F,F,F,F,F,F,F,F,F,F,F,F,F,F,F,F,F,F,F,F,F,F,F,F\
,F,F,F,F,F,F,F,F,F,F,F,F,F,F,F,F,F,F,F,F,F,F,F,F,F,F,F,F,F,F,UR);
printf("%c welcome to the Dragonstorm multi-function calculator %c\n",VERT,VERT);
printf("%c Please type the number of your selection %c\n",VERT,VERT);
printf("%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c\n",LT,F,F,F,F,F,F\
,F,F,F,F,F,F,F,F,F,F,F,F,F,UPT,F,F,F,F,F,F,F,F,F,F,F,F,F,F,F,\
F,F,F,F,F,F,F,UPT,F,F,F,F,F,F,F,F,F,F,F,F,F,F,F,F,F,F,F,F,F,F,RT);
// printf("%c %c\n",VERT,VERT);
printf("%c Number to press: %cHere Are Your Options:%cINFO: %c\n",VERT,VERT,VERT,VERT);
printf("%c1) %cHypotenuse calculator %cinsert side a&b legnth%c\n",VERT,VERT,VERT,VERT);
printf("%c2) %cReverse hypot. calc. %cinsert hypot. &1 side %c\n",VERT,VERT,VERT,VERT);
printf("%c3) %cBasic calculator %cinsert # and operation%c\n",VERT,VERT,VERT,VERT);
printf("%c %c %c %c\n",VERT,VERT,VERT,VERT);
printf("%c Press x and - %c -enter to quit %c %c\n",VERT,VERT,VERT,VERT);
printf("%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c\n",DL,F,F,F,F,F,F\
,F,F,F,F,F,F,F,F,F,F,F,F,F,DWNT,F,F,F,F,F,F,F,F,F,F,F,F,F,F,F\
,F,F,F,F,F,F,F,DWNT,F,F,F,F,F,F,F,F,F,F,F,F,F,F,F,F,F,F,F,F,F,F,DR);
}
void clearscreen()
{
if (system( "clear" )) system( "cls" );
}
hypotenuse function.c
float HYPOTENUSE_F()
{
float sideC,sideA,sideB,temp;//declare variables used for equation(the theory of pythag.(a²+b²=c²)
char A[2000],B[2000];
int choice;//for menu
STARTHE:
printf("Please do not add cm or m extensions only the number itself.\n\n");
printf("Please give the legnth of a and then press enter.\n");
_flushall();
gets(A);
printf("\nPlease give the legnth of b and then press enter.\n");
_flushall();
gets(B)/>;
sideA=atof(A);
sideB=atof(B)/>;
sideA=(sideA*sideA);
sideB=(sideB*sideB);
temp=sideA+sideB;
sideC=sqrt(temp);
printf("The legnth of the hypotenuse is %f\n",sideC);
printf("\nWould you like to perform the same action with different numbers?(y/n)\n");
_flushall();
choice=getchar();
switch (choice)
{
case'y':
clearscreen();
goto STARTHE;
default:
clearscreen();
}
return 0;
}
Hypotenuse reverse function.c
float HYPOTENUSER_F()
{
float continue2;//declare continuation variable
float sideC,sideA,sideB;//declare variables used for equation(the theory of pythag.(a²+b²=c²)
char C[2000],B[2000];
int choice;//for menu
STARTHE:
printf("Please do not add cm or m extensions only the number itself.\n\n");
printf("Please give the legnth of the hypotenuse.\n");
_flushall();
gets(C);
printf("\nPlease give the legnth of the known side.\n");
_flushall();
gets(B)/>;
sideC=atof(C);
sideB=atof(B)/>;
sideC=(sideC*sideC);
sideB=(sideB*sideB);
sideA=sideC-sideB;
sideA=sqrt(sideA);
printf("The legnth of the side is %f\n",sideA);
printf("\nWould you like to perform the same action with different numbers?(y/n)\n");
_flushall();
choice=getchar();
switch (choice)
{
case'y':
clearscreen();
goto STARTHE;
default:
clearscreen();
}
return 0;
}
normal calculator.c
float BASIC_CALCULATOR_F(void)
{
char op,choice,A[2000],B[2000];
int operation;
float answer;
float A2,B2;
STARTS:
A2=0;
B2=0;
printf("Please enter the first number\n\n");
_flushall();
gets(A);
printf("Please enter operation\n");
_flushall();
operation=getchar();
printf("Please enter the second number\n");
_flushall();
gets(B)/>;
A2=atof(A);
B2=atof(B)/>;
switch(operation)
{
case'+':
answer=A2+B2;
goto PANS;
case '-':
answer=A2-B2;
goto PANS;
case 'x':
answer=A2*B2;
goto PANS;
case'*':
answer=A2*B2;
goto PANS;
case'^':
answer=pow(A2,B2);
goto PANS;
default:
printf("Sorry that is an invalid selection\n");
}
PANS:
printf("the answer is %f\n",answer);
printf("\nWould you like to perform the same action with different numbers?(y/n)\n");
_flushall();
choice=getchar();
switch (choice)
{
case'y':
clearscreen();
goto STARTS;
case'Y':
clearscreen();
goto STARTS;
default:
clearscreen();
}
}
...and that's it,can anyone help me to improve and optimize this script?,thank you.

New Topic/Question
Reply



MultiQuote







|