Initial version:
#include <stdio.h>
int Checkpassword ();
int add (int x,int y);
int sub (int x,int y);
int multi (int x,int y);
Float Quo (float x1,float y1);
int com (int x,int y);
int x, y;
int result;
int select;
float RESULT1;
float x1,y1;
int SUCCESS,PSW;
int A;
int i;
int t;
void Main ()
{
printf ("Please enter password: \ n");
i=0;
do{
scanf ("%d", &a);
if (a!=1234 && i<2)
printf ("Please reenter password: \ n");
Else
i=3;
i++;
}while (i<=2);
if (a==1234)
{
for (T=1;t!=6;t=select)
{
printf ("+=============================+\n");
printf ("+====== = = = = = Main = Dish = Single ======+\n");
printf ("+=============================+\n");
printf ("+==========1, Addition ==========+\n");
printf ("+==========2, Subtraction ==========+\n");
printf ("+==========3, multiplication ==========+\n");
printf ("+==========4, Division ==========+\n");
printf ("+==========5, seeking ==========+\n");
printf ("+==========6, Exit ==========+\n");
printf ("+=============================+\n");
printf ("Please enter your choice: \ n");
scanf ("%d", &select);
Switch (SELECT)
{
Case 1:
printf ("Please enter two number: \ n");
scanf ("%d%d", &x,&y);
Result=add (x, y);
printf ("%d+%d=%d\n", X,y,result);
Break
Case 2:
printf ("Please enter two number: \ n");
scanf ("%d%d", &x,&y);
Result=sub (x, y);
printf ("%d-%d=%d\n", X,y,result);
Break
Case 3:
printf ("Please enter two number: \ n");
scanf ("%d%d", &x,&y);
Result=multi (x, y);
printf ("%d*%d=%d\n", X,y,result);
Break
Case 4:
printf ("Please enter two number: \ n");
scanf ("%f%f", &x1,&y1);
Result1=quo (X1,Y1);
printf ("%f/%f=%f\n", X1,Y1,RESULT1);
Break
Case 5:
printf ("Please enter two number: \ n");
scanf ("%d%d", &x,&y);
Result=com (x, y);
printf ("%d/%d=%d\n", X,y,result);
Break
Case 6:
Break
Default
printf ("Please enter the number of" between the numbers \ n ");
Break
}
}
}
}
int add (int x,int y)
{
int sum;
Sum=x+y;
return sum;
}
int sub (int x,int y)
{
int sub;
Sub=x-y;
return sub;
}
int multi (int x,int y)
{
int multi;
Multi=x*y;
return multi;
}
Float Quo (float x,float y)
{
float quo;
quo=x/y;
Return quo;
}
int com (int x,int y)
{
int com;
com=x%y;
return COM;
}
int Checkpassword (int psw)
{
if (psw==1234)
Success=1;
Else
Success=-1;
return success;
}
After the revision:
#include <stdio.h>
int Yanzheng (int);
void Caidan ();
void Jiafa (Int,int);
void Jianfa (Int,int);
void Chengfa (float,float);
void Chufa (float,float);
void Mo (Int,int);
void Main () {
int x,m;
int y;
float A, B;
printf ("Please enter password: \ n");
scanf ("%d", &x);
M=yanzheng (x);
if (m==1) {
Caidan ();
int y;
float A, B;
for (; y!=6;) {
printf ("Please enter option: \ n");
scanf ("%d", &y);
if (y>=1 && y<6) {
printf ("Please enter two numbers to operate: \ n");
scanf ("%f%f", &a,&b);
}
Switch (y) {
Case 1:jiafa (A, b);
Case 2:jianfa (A, b);
Case 3:CHENGFA (A, b);
Case 4:chufa (A, b);
Case 5:mo (A, b);
Case 6:break;
default:printf ("option input Error! Please retry \ n ");
}
}
}
}
int Yanzheng (int x) {
int i,m;
for (i=1,m=0;i<3;i++) {
if (x==1234) {
M=1;
Break
}
printf ("Please re-enter password:");
scanf ("%d", &x);
}
return m;
}
void Caidan () {
printf ("+=============================+\n");
printf ("+====== = = = = = Main = Dish = Single ======+\n");
printf ("+=============================+\n");
printf ("+==========1, Addition ==========+\n");
printf ("+==========2, Subtraction ==========+\n");
printf ("+==========3, multiplication ==========+\n");
printf ("+==========4, Division ==========+\n");
printf ("+==========5, seeking ==========+\n");
printf ("+==========6, Exit ==========+\n");
printf ("+=============================+\n");
}
void Jiafa (int x,int y) {
int sum;
Sum=x+y;
printf ("%d\n", sum);
}
void Jianfa (int x,int y) {
int cha;
Cha=x-y;
printf ("%d\n", cha);
}
void Chengfa (float x,float y) {
float Ji;
Ji=x*y;
printf ("%f\n", Ji);
}
void Chufa (float x,float y) {
float Shang;
shang=x/y;
printf ("%f\n", Shang);
}
void Mo (int x,int y) {
int mo;
mo=x%y;
printf ("%d\n", MO);
}
A simple calculator written in C language