# Calculator in C

Discussion in 'C' started by Adarsh sojitra, Oct 4, 2013.

Joined:
Oct 4, 2013
Messages:
3
0
Trophy Points:
0
Code:
```/*PROGRAMMER: SOJITRA AADARSH

DATE:22/8/2013

AGE: 16 YEARS

main()

{

char ab[50];
float a,ans;
char o;
clrscr();
ans=0;

printf("\n Press A for help");

while(1)
{

printf("\n\n Enter opertor and number: ");
fgets(ab,sizeof(ab),stdin);
sscanf(ab,"%c %f",&o,&a);

if((o=='a')||(o=='A'))
{
clrscr();
printf("\n Enter operator and number to calculate.");
printf("\n Do not put space between operator and number.");
printf("\n Enter N or n to quit.");
printf("\n Press c or C to clear screen.");
printf("\n To reset multiply with 0.");
printf("\n You can calculate form -3.4e-38 to +3.4e-38.");
printf("\n The answer will be 0 first time when you are calcutating from this window.");
printf("\n\n Enter opertor and number: ");
fgets(ab,sizeof(ab),stdin);
sscanf(ab,"%c %.3f",&o,&a);
}

if((o=='c')||(o=='C'))
{

clrscr();
printf("\n\n Enter opertor and number: ");
fgets(ab,sizeof(ab),stdin);
sscanf(ab,"%c %.3f",&o,&a);

}

if((o=='N')||(o=='n'))

{

printf("\n\t\t\tPress any key to quit............");
break;

}

switch(o)

{

case'+':ans+=a;
break;
case'-':ans-=a;
break;
case'*':ans*=a;
break;
case'/':if(a==0)

{
printf("\n\t\t\t\t    !ERROR!");
printf("\n\t\t\t     Operation is cancelled");
}

else

{

ans/=a;

}

break;
default:printf("\n\n Error in operator");
break;

}

}

getch();

return 0;
}
:cool:
```