I was writing the following C code on Centos 6.5 using gcc-4.7 but program does not waiting for Type Y/N: statement it immediately exits after result.Either of the codes are not working.
#include <stdio.h>
int main()
{
int a,b;
char ch='y';
do
{
printf("Enter Number 1:\n");
scanf("%d",&a);
printf("Enter Number 2:\n");
scanf("%d",&b);
printf("Result is:%d\n",a+b);
printf("Type y/N:\n");
scanf("%c",&ch);
}while(ch=='y' || ch=='Y');
}
return 0;
}
OR
#include<stdio.h>
int main()
{
int a,b;
char ch='y';
while(ch=='y' || ch=='Y')
{
printf("Enter Number 1:\n");
scanf("%d",&a);
printf("Enter Number 2:\n");
scanf("%d",&b);
printf("Result is:%d\n",a+b);
printf("Type y/N:\n");
scanf("%c",&ch);
}
return 0;
}