#include <stdio.h>
#include <ctype.h>
/*************
Description: display_menu (only displays menu)
Parameters in: N/A
Parameters out: N/A
Return: N/A
*************/
void display_menu ( void )
{
printf ( "You have 4 choices." ) ; printf ( "Enter a for my name." ) ; printf ( "Enter b for my tutorial date." ) ; printf ( "Enter c to read a positive number & display all numbers." ) ;
return ;
}
/*************
Description: get_choice
Parameters in: N/A
Parameters out: response
Return: Users choice.
*************/
char get_choice ( void )
{
char response;
//response = getchar();
scanf ( "%c%*c" ,& response
) ;
return ( response) ;
}
/*************
Description: menu
Parameters in: choice
Parameters out: N/A
Return: Doesnt return, process the user choice.
*************/
void performe_action ( char choice)
{
switch ( choice)
{
case 'a' :
print_name( ) ;
break ;
case 'b' :
print_lab( ) ;
break ;
case 'c' :
get_calculate_number( ) ;
default :
}
return ;
}
/*************
Description: Print function - name
Parameters in: N/A
Parameters out: N/A
Return: N/A
*************/
void print_name ( void )
{
printf ( "My name is bla bla" ) ;
return ;
}
/*************
Description: Print function - lab time
Parameters in: N/A
Parameters out: N/A
Return: N/A
*************/
void print_lab ( void )
{
printf ( "My lab is on bla bla" ) ;
return ;
}
/*************
Description: get and calculate number
Parameters in: get number from function get_number
Parameters out: print the result from print_number
Return: N/A
*************/
void get_calculate_number ( void )
{
int number;
number = get_number( ) ;
print_number( number) ;
return ;
}
/*************
Description: get a number
Parameters in: N/A
Parameters out: number choice
Return: N/A
*************/
int get_number ( void )
{
int number;
printf ( "What is your number" ) ; scanf ( "%d%*c" , & number
) ;
return ( number) ;
}
/*************
Description: get a number
Parameters in: N/A
Parameters out: number choice
Return: N/A
*************/
void print_number( int number)
{
int x;
for ( x= 1 ; x<= number; x++ )
{
printf ( "The result is %d" , x
) ; }
return ;
}
int main( )
{
char choice;
do {
display_menu( ) ;
choice = get_choice( ) ;
performe_action( choice) ;
} while ( choice != 'q' ) ;
return ( 0 ) ;
}
I2luY2x1ZGUgPHN0ZGlvLmg+CiNpbmNsdWRlIDxjdHlwZS5oPgoKCi8qKioqKioqKioq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