i am a newbie in C programming, and this program is giving errors... pls help?

stanzinotsal

New member
Joined
Dec 22, 2010
Messages
1
Reaction score
0
Points
1
//call by value example
int calc(int var1,int var2,char oper);
main()
{
int num1,num2;
char operator;

printf(";enter two no.s and an operator\n");
scanf("%d%d%d",&num1,&num2,&operator);
calc(num1,num2,operator);
getch();
}
calc(var1,var2,oper)
{
int var1,var2;
char oper;
switch(oper)
{
case '*':
printf("%d",var1*var2);
break;
case '/':
printf("%d",var1/var2);
break;
case '-':
printf("%d",var1-var2);
break;
case'+':
printf("%d",var1-var2);
break;
default:
printf(" do as you are told \n");
}
 
try this i have specified ur error

//call by value example
main()
{
int num1,num2;
char operator;

printf(";enter two no.s and an operator\n");
scanf("%d%d%c",&num1,&num2,&operator); //use %c to read char since operator is char
calc(num1,num2,operator);
getch();
}
void calc(int var1,int var2,char oper) //use void if u use int it should return a integer value
{
//dont initialize var1,var2 and oper again
switch(oper)
{
case '*':
printf("%d",var1*var2);
break;
case '/':
printf("%d",var1/var2);
break;
case '-':
printf("%d",var1-var2);
break;
case'+':
printf("%d",var1-var2);
break;
default:
printf(" do as you are told \n");
}


Next time if u ask question do list ur errors
 
Back
Top