fork download
  1. #include <stdio.h>
  2. #include <ctype.h>
  3.  
  4.  
  5. /*************
  6. Description: display_menu (only displays menu)
  7. Parameters in: N/A
  8. Parameters out: N/A
  9. Return: N/A
  10. *************/
  11. void display_menu (void)
  12. {
  13. printf("You have 4 choices.");
  14. printf("Enter a for my name.");
  15. printf("Enter b for my tutorial date.");
  16. printf("Enter c to read a positive number & display all numbers.");
  17. printf("Enter q to quit.\n");
  18.  
  19. return;
  20. }
  21.  
  22. /*************
  23. Description: get_choice
  24. Parameters in: N/A
  25. Parameters out: response
  26. Return: Users choice.
  27. *************/
  28. char get_choice (void)
  29. {
  30. char response;
  31. //response = getchar();
  32. scanf("%c%*c",&response);
  33. response = tolower(response);
  34.  
  35. return(response);
  36. }
  37.  
  38. /*************
  39. Description: menu
  40. Parameters in: choice
  41. Parameters out: N/A
  42. Return: Doesnt return, process the user choice.
  43. *************/
  44. void performe_action (char choice)
  45. {
  46. switch (choice)
  47. {
  48. case 'a':
  49. print_name();
  50. break;
  51. case 'b':
  52. print_lab();
  53. break;
  54. case 'c':
  55. get_calculate_number();
  56. default:
  57. printf("Invalid input\n");
  58. }
  59.  
  60. return;
  61. }
  62.  
  63. /*************
  64. Description: Print function - name
  65. Parameters in: N/A
  66. Parameters out: N/A
  67. Return: N/A
  68. *************/
  69. void print_name (void)
  70. {
  71. printf ("My name is bla bla");
  72.  
  73. return;
  74. }
  75.  
  76. /*************
  77. Description: Print function - lab time
  78. Parameters in: N/A
  79. Parameters out: N/A
  80. Return: N/A
  81. *************/
  82. void print_lab (void)
  83. {
  84. printf ("My lab is on bla bla");
  85.  
  86. return;
  87. }
  88.  
  89. /*************
  90. Description: get and calculate number
  91. Parameters in: get number from function get_number
  92. Parameters out: print the result from print_number
  93. Return: N/A
  94. *************/
  95. void get_calculate_number (void)
  96. {
  97. int number;
  98.  
  99. number = get_number();
  100. print_number(number);
  101.  
  102. return;
  103. }
  104.  
  105. /*************
  106. Description: get a number
  107. Parameters in: N/A
  108. Parameters out: number choice
  109. Return: N/A
  110. *************/
  111. int get_number (void)
  112. {
  113. int number;
  114.  
  115. printf ("What is your number");
  116. scanf ("%d%*c", &number);
  117.  
  118. return(number);
  119. }
  120.  
  121. /*************
  122. Description: get a number
  123. Parameters in: N/A
  124. Parameters out: number choice
  125. Return: N/A
  126. *************/
  127. void print_number(int number)
  128. {
  129. int x;
  130.  
  131. for(x=1; x<=number; x++)
  132. {
  133. printf ("The result is %d", x);
  134. }
  135.  
  136. return;
  137. }
  138.  
  139. int main()
  140. {
  141. char choice;
  142.  
  143. do {
  144. display_menu();
  145. choice = get_choice();
  146. performe_action(choice);
  147. } while (choice != 'q');
  148.  
  149. return(0);
  150. }
Success #stdin #stdout 0s 2252KB
stdin
a
q
stdout
You have 4 choices.Enter a for my name.Enter b for my tutorial date.Enter c to read a positive number & display all numbers.Enter q to quit.
My name is bla blaYou have 4 choices.Enter a for my name.Enter b for my tutorial date.Enter c to read a positive number & display all numbers.Enter q to quit.
Invalid input