#include
remove the getch inside the while loop
yes i will try and see now.. but how would that matter?
no.. its still the same... even if i remove getch it is happening just once.. den if i type y or n it is not going further..
let me check it wait
#include<stdio.h> #include<conio.h> main() { char a; int num; do { printf("\nEnter a number\n"); scanf("%d",&num); printf("the square of %d is %d",num,num*num); printf("\nWant to enter another number y or n"); a=getchar(); } while(getchar()=='y') ; getch(); }
when the scanf("%c",&a); statement was executed you typed y and hitted enter but ecuz of hitting enter a \n character was also inserted in a thats y the value of a became y and a \n which make the while loop false and nothing was coming again , sos to take one character as an input use getchar() method
use void main() or int main() & return 0; in the end ...... should complete these things..
Join our real-time social learning platform and learn together with your friends!