Simple menu options in C Language

Source: Internet
Author: User

Simple menu options in C Language

#include 
 
  char get_choice(void);char get_first(void);int get_int(void);void count(void);int main(){int choice;void count (void);
 
While (choice = get_choice ())! = 'Q') {switch (choice) {case 'A': printf ("Buy low, shell high \ n"); break; case 'B ': putchar ('\ A'); break; case 'C': count (); break; default: printf ("Buy adbcxz \ n"); break ;}} printf ("Bye. \ n "); return 0;} void count (void) {int n, I; printf (" Count how far? Enter an integer: \ n "); n = get_int (); for (I = 1; I <= n; I ++) {printf (" % d \ n ", i);} while (getchar ()! = '\ N') continue;} char get_choice (void) {char ch; printf ("Enter the letter of your choice: \ n"); printf (". advice B. bell \ n "); printf (" c. count d. quit \ n "); ch = get_first (); while (ch <'A' | ch> 'C') & ch! = 'Q') {printf ("please respond with a, B, c, or q \ n"); ch = get_first ();} return ch ;} // obtain the input string char get_first (void) {char ch; ch = getchar (); while (getchar ()! = '\ N') continue; return ch;} int get_int (void) {int input; char ch; while (scanf ("% d", & input )! = 1) {while (ch = getchar ())! = '\ N') putchar (ch); printf ("is not an integer. \ n please enter an "); printf (" integer value, such as 25,-178, or 3: ") ;}return input ;}

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.