Wednesday 18 May 2011

Create a Calculator by using if-else statement

Just copy the code...


#include<stdio.h>
#include<conio.h>
void main (void)
{
 char ch;
 float num1,num2;
 clrscr();
 printf("What do you want to do?\n");
 printf("Addition, Subtraction, Multiplication or Division:");
 ch=getche();
 printf("\nEnter first number:");
 scanf("%f",&num1);
 printf("\nEnter second number:");
 scanf("%f",&num2);
 printf("\n\n");


if(ch=='A')   
 printf("%f %c %f = %.2f",num1,+,num2,num1+num2);

if(ch=='S')   
 printf("%f %c %f = %.2f",num1,-,num2,num1-num2);
if(ch=='M')   
 printf("%f %c %f = %.2f",num1,*,num2,num1*num2);
if(ch=='D')   
 printf("%f %c %f = %.2f",num1,/,num2,num1/num2);
getch();  



}


What is this?



4 comments:

Unknown said...

it's does'nt show the result

MuzammilVersiani said...

@sahil afridi make sure you are pressing one of these keys: A, S, M or D otherwise it will not show anything.

RSLDB Jaipur said...

code is incorrect, error in compilation
||=== Build file: "no target" in "no project" (compiler: unknown) ===|
C:\Users\hp 4\Desktop\Programming\pg.c||In function 'main':|
C:\Users\hp 4\Desktop\Programming\pg.c|19|error: expected expression before ',' token|
C:\Users\hp 4\Desktop\Programming\pg.c|21|error: expected expression before ',' token|
C:\Users\hp 4\Desktop\Programming\pg.c|23|error: expected expression before ',' token|
C:\Users\hp 4\Desktop\Programming\pg.c|25|error: expected expression before '/' token|
||=== Build failed: 4 error(s), 0 warning(s) (0 minute(s), 0 second(s)) ===|

Farabi Sajib said...

Error

Post a Comment