samedi 18 février 2017

why are the if conditions not being executed?

Its a menu driven program.asking for users choice . why are if condtions not executed? OUTPUT IS ATTACHED CREATING A PROGRAM ASKING FOR USERS INPUT.

 void main()

{  
 float a,b,ans=0;char ch,choice;


   choice='y';

while(choice=='Y'||choice=='y')
 {


 printf("Enter two numbers \n");
 scanf("%f %f",&a,&b);
 printf("1.+for Addition\n");
 printf("2.-for subtraction \n");
 printf("3.*for multiplication \n ");
 printf("4./for Division \n");
 printf("Enter your choice of operation \n");
 scanf("%c",&ch);

if(ch=='+')
 ans=a+b;
else if (ch=='-')
    ans=a-b;
else if(ch=='*')
 ans=a*b;
else if(ch=='/')
    ans=a/b;
else
{
  printf("wrong choice entered\n");
}
printf("Answer is %f \n",ans);
printf("Do you want to coninue (Y/N)\n");
scanf("%c",&choice);
 }

  printf("program Terminated\n");
  }


/* Enter two numbers
1010
22
1.+for Addition
2.-for subtraction
3.*for multiplication
4./for Division
Enter your choice of operation
wrong choice entered
Answer is 0.000000
 Do you want to coninue (Y/N)
 n
  program Terminated
    */

THE ABOVE IS THE OUPTUT SCREEN. it doesnt perform operations.

Aucun commentaire:

Enregistrer un commentaire