|
|
|||||||||
|
|||||||||
| |||||||||
|
|
|
| |||||||||
![]() |
|
|
«
Previous Thread
|
Next Thread
»
|
Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
|
|
Be the architects of evolution and help create the mobile internet future. It’s your move---enter to win here! |
|
#1
|
|||
|
|||
|
Need help making an infinite loop
hello im a bit stuck i want to make an infinite loop for my program but not sure how
i want the program to display Do You want to Continue Y/N ? On the user typing "Y" the program will run again On the user typing "N" the program ends How do i do this ? Where would be a good place to put the code ? Can anyone help please? |
|
#2
|
||||
|
||||
|
There's more than one way to do it!
Code:
while (1) {
printf("Do you want to run this again? (Y/N) ");
ch = getch();
if (ch == 'N' || ch == 'n')
break;
else if (ch == 'Y' || ch == 'y') {
.... your code comes here
}
else
printf ("Dammit! I said type Y or N\n");
}
|
|
#3
|
|||
|
|||
|
another one:
Code:
char ch='J';
while (ch=='j'||ch=='J') {
... run code ...
do {
printf("Do you want to run this again? (Y/N) ");
ch = getch();
} while (ch!='J' && ch!='j' && ch!='n' && ch!='N');
}
__________________
-- Manuel Hirsch - Linux, FreeBSD, programming, administration articles, tutorials and more. |
|
#4
|
|||
|
|||
|
thanks for your help everyone ive got the loop working perfectly
![]() |
![]() |
| Viewing: Dev Shed Forums > Programming Languages > C Programming > Need help making an infinite loop |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|
|
|