here in this program num1 value is changing into zero inside if- else condition. i am getting wrong answer as the variable is automatically becoming 0. why is that? if i give num1 as 4 and num2 as 3. i am getting added value as 3, it should be 7 right. kindly help to solve
#include<stdio.h>
void main()
{
int num1, num2, answer;
char type;
printf("Enter num1\n");
scanf("%d",&num1);
printf("Enter num2\n");
scanf("%d",&num2);
printf("type a for addition or s for subtraction\n");
scanf("%s",&type);
if(type == 'a')
{
answer = num1 + num2;
printf("answer is %d \n",add);
}
else if(type == 's')
{
answer = num1 - num2;
printf("answer is %d \n",sub);
}
else
{
printf("enter a or s");
}
}
Aucun commentaire:
Enregistrer un commentaire