Ask your own question, for FREE!
Computer Science 21 Online
OpenStudy (akshay_budhkar):

#include #include main() { clrscr(); char a='y'; int num; while(a=='y') { 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"); scanf("%c",&a); getch(); } getch(); } whats wrong in this.. its not going ahead even if i type y..

OpenStudy (anonymous):

remove the getch inside the while loop

OpenStudy (akshay_budhkar):

yes i will try and see now.. but how would that matter?

OpenStudy (akshay_budhkar):

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..

OpenStudy (anonymous):

let me check it wait

OpenStudy (anonymous):

#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(); }

OpenStudy (anonymous):

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

OpenStudy (anonymous):

use void main() or int main() & return 0; in the end ...... should complete these things..

Can't find your answer? Make a FREE account and ask your own questions, OR help others and earn volunteer hours!

Join our real-time social learning platform and learn together with your friends!
Can't find your answer? Make a FREE account and ask your own questions, OR help others and earn volunteer hours!

Join our real-time social learning platform and learn together with your friends!