I want to find square of different numbers . I am using do while loop so that after calculating square of 1st number it will ask me to whether I want to find squre of another number or not.
But problem is when I give answer choice as 'y' or 'Y' or any character,it returns to editor window only without calculating sqaure of 2nd number and showing no error. So what's wrong in my program ?
#include<stdio.h>
#include<conio.h>
void main()
{
int num,sqr;
char ans;
do
{
printf("enter the number:\n");
scanf("%d",&num);
sqr=num*num;
printf("square is %d",sqr);
printf("\ndo you want to continue?");
scanf("%c",&ans);
}while(ans=='y'|| ans=='Y');
getch();
}