Soldato
- Joined
- 5 Aug 2006
- Posts
- 11,419
- Location
- Derbyshire
Trying to do the following tutorial question, but got a bit stuck!
The program needs to repeatedly ask the user for a choice, then it should keep looping back to the start unless the user types 'end'.
Here is what I have so far - I cannot have user_reply at the while bit as it is an integer (I have done this currently but unsure how to correct it!)
#include <stdio.h>
int main(void)
{
char user_reply;
do
{
fprintf(stdout," Select option (0, 1, 2, 3 or 4):");
scanf("%d", &user_reply);
switch(user_reply)
{
case 0: fprintf(stdout,"You chose option 0\n");
break;
case 1: fprintf(stdout,"You chose option 1\n");
break;
case 2: fprintf(stdout,"You chose option 2\n");
break;
case 3: fprintf(stdout,"You chose option 3\n");
break;
case 4: fprintf(stdout,"You chose option 4\n");
break;
default: printf,(stdout,"Error, invalid selection\n");
}
}while (user_reply !="end");
return(0);
}
The program needs to repeatedly ask the user for a choice, then it should keep looping back to the start unless the user types 'end'.
Here is what I have so far - I cannot have user_reply at the while bit as it is an integer (I have done this currently but unsure how to correct it!)
#include <stdio.h>
int main(void)
{
char user_reply;
do
{
fprintf(stdout," Select option (0, 1, 2, 3 or 4):");
scanf("%d", &user_reply);
switch(user_reply)
{
case 0: fprintf(stdout,"You chose option 0\n");
break;
case 1: fprintf(stdout,"You chose option 1\n");
break;
case 2: fprintf(stdout,"You chose option 2\n");
break;
case 3: fprintf(stdout,"You chose option 3\n");
break;
case 4: fprintf(stdout,"You chose option 4\n");
break;
default: printf,(stdout,"Error, invalid selection\n");
}
}while (user_reply !="end");
return(0);
}