what is the best way to have a menu and
ask for input and check for it.
this is what i have so far, its not finished
but i feel im not doing it right
Code:
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <ctype.h>
#define MAXCUST 12
struct airline {
unsigned int seat;
char customer[MAXCUST];
};
char showmenu ( void );
int main(int argc, char *argv[])
{
struct airline seat[BUFSIZ];
char choice;
while ( ( choice = showmenu() )!= 'f' );
{
switch ( choice )
{
case 'a' : printf(" you hit a");
break;
case 'b' : printf(" you hit b");
break;
}
system("PAUSE");
return 0;
}
}
char showmenu ( void )
{
char ans;
printf(" ********** Welcome to Swift Lines Airlines ************\n");
printf("\n ********** To Choose A Function, Enter its Letter Label:\n");
printf("\na ) Show Number of seats\n");
printf("b ) Show List of seats\n");
printf("c ) Show alphabetical list of seats\n");
printf("d ) Assign a Customer to a seat assignment\n");
printf("e ) Delete a seat assignment\n");
printf("f ) Quit\n");
ans = getchar();
ans = tolower( ans );
while ( strchr ( "abcdef" , ans ) == NULL )
{
puts( " please pick A - F :\n");
ans = tolower( getchar() );
}
return ans;
}
output:
Code:
********** Welcome to Swift Lines Airlines ************
********** To Choose A Function, Enter its Letter Label:
a ) Show Number of seats
b ) Show List of seats
c ) Show alphabetical list of seats
d ) Assign a Customer to a seat assignment
e ) Delete a seat assignment
f ) Quit
a
********** Welcome to Swift Lines Airlines ************
********** To Choose A Function, Enter its Letter Label:
a ) Show Number of seats
b ) Show List of seats
c ) Show alphabetical list of seats
d ) Assign a Customer to a seat assignment
e ) Delete a seat assignment
f ) Quit
please pick A - F :
why is it doing this?
thanks