+ 2
do-while loop
Hallo guys, char choice; do{ char name[10]; printf("Enter a name: "); scanf("%s",&name); printf("Hi, my name is %s\n",name); printf("Press (j)to end or press(n)to enter a new name: "); choice=getchar(); }while(choice=='n'); At the end of the do-while loop I want to Input 'n', so that the condition evaluates to true and to reinitialize the variable 'name', but doesn't work. Can somebody please help me?
1 Antwort
+ 2
You can do this by goto statement like:
int choice;
char name[10];
loop :
printf("Enter Name : ");
scanf ("%s",name);
printf("Name : %s\n",name);
printf ("If you want to rename than press 1.\n If you want to exit then press 0.\n");
scanf ("%d",& choice);
if(choice==1)
{
goto loop;
}
else
{
exit (0);
}