-
how to run this program in do while loop
over 3 years ago
-
about 3 years ago
Hi, I'm a C++ programmer but basically there were some errors. You didn't initiaize y. Therefore the do loop stops after the first iteration because it is not 'y'. Furthermore,, it works for me if I change the type in the last scanf. Hope that helps. Cheers, Konrad #includeint main() { int num; char* another; *another = 'y'; do { printf("enter the number"); scanf("%d", &num); printf("the square is %d" ,num*num); printf("want another y/n"); scanf("%s", another); }while(*another =='y'); return 0; } -
-
about 3 years ago
Hi,
you did not initialize another. Thus the program ends after the first loop iteration.
Furthermore I think the last scanf is not correct.
Here the code that worked on my machine.
Cheers,
Konrad
#include<stdio.h>
int main()
{
int num;
char* another;
*another = 'y';
do
{
printf("enter the number");
scanf("%d", &num);
printf("the square is %d" ,num*num);
printf("want another y/n");
scanf("%s", another);
}while(*another =='y');
return 0;
}
-
2 Answer(s)