English Deutsch Français Italiano Español Português 繁體中文 Bahasa Indonesia Tiếng Việt ภาษาไทย
All categories

I wrote a programme in C, but switch case is not working. when PRESS 1 or 2 or others then it says that it is wrong choice. tell me what problem it has.
I wrote a programme of calculator in C language. And it has two or three error so pl do correct them. And send me correct answer.
Prog. is:

#include
#include
void calsum(int a,int b);
void calsub(int a,int b);
void calmul(int a,int b);
void caldiv(float a,float b);
/*void calmod(int a,int b); */
void calsqr(int a);
void calcue(int a);
void calfac(long int a);
void main()
{
int l,m,n,ch;
clrscr();
printf("\t\t==========\n");
printf("\t\t Menu ");
printf("\t\t==========\n");
printf("\t\t 1 Add\n");
printf("\t\t 2 Sub\n");
printf("\t\t 3 Mul\n");
printf("\t\t 4 Div\n");
printf("\t\t 5 Factorail\n");
printf("\t\t 6 Square\n");
printf("\t\t 7 Cube\n");
/*printf("\t\t 8 Mod\n"); */
printf("\t\t Enter your choice \n");
scanf("%d",ch);
printf("\t\t =====\t");
switch(ch)
{
case 1:
printf("\t\tEnter two number : ");
scanf("%d%d",&l,&m);
calsum(l,m);
break;
case 2:
printf("\t\tEnter two numbers " );
scanf("%d%d",&l,&m);
calsub(l,m);
break;
case 3:
printf("\t\t Enter two numbers" );
scanf("%d%d",&l,&m);
calmul(l,m);
break;
case 4:
printf("\t\t Enter two numbers : ");
scanf("%s%s",&l,&m);
caldiv(l,m);
break;
case 5:
printf("\t\t Enter any no : ");
scanf("%ld",&l);
calfac(l);
break;
case 6:
printf("\t\t Enter any no : ");
scanf("%d",&l);
calsqr(l);
break;
case 7:
printf("\t\t Enter any no : ");
scanf("%d",&l);
calcue(l);
break;
/*
case 8:
printf("\t\t Enter any no : ");
scanf("%d",&l);
calmod(l);
break;*/
default:
printf("\t It is wrong choice : ");
}
getch();
}
void calsum(int a,int b)
{
int c;
c=a+b;
printf("Addition=%d",c);
}
void calsub(int a,int b)
{
int c;
c=a-b;
printf("Substance=%d",c);
}
void calmul(int a,int b)
{
int c;
c=a*b;
printf("Multiply=%d",c);
}
void caldiv(float a,float b)
{
float c;
c=a/b;
printf("Divide=%d",c);
}
void calsqr(int a)
{
int c;
c=a*a;
printf("Square=%d",c);
}
void calcue(int a)
{
int c;
c=a*a*a;
printf("Cube=%d",c);
} /*
void calmod(int a,int b)
{
int c;
c=a%b;
printf("Mod=%d",c);
} */
void calfac(long int a)
{
long int i,fct;
fct=1;
for(i=a;i>=1;i--)
{
fct=fct*i;
}
printf("Factorail=%d",fct);
}

2006-10-18 12:32:54 · 3 answers · asked by Pushpendra 1 in Computers & Internet Programming & Design

3 answers

scanf("%d",ch); should be: scanf("%d",&ch);

2006-10-19 02:27:51 · answer #1 · answered by justme 7 · 0 0

Your compiler should tell you where the errors are -- you are compiling this, right? justme showed you one of your problems. Also, you might want to check the format you specified when scanning in floating point numbers for caldiv().

2006-10-19 07:17:39 · answer #2 · answered by Questioner 2 · 0 0

In otherwords: "Please do my homework for me" . Nice.

2006-10-18 12:40:20 · answer #3 · answered by Isle Flyer 3 · 1 1

fedest.com, questions and answers