How to Create All in One Menu Driven Program in C Language

All in One Menu Driven Program in C Language

Introduction :

The menu driven program is a common program in the programming world. There are lists of options in a menu driven program. From the options, user can select an option to perform a specific task or operation. Creating an all in one menu driven program in C or C++ graphics programming language is an interesting and educational project for developing.

Menu driven program gives a user-friendly interface by which user can perform various tasks (mathematical and logical operations) based on his input in the menu system. In this article, I shall explore you how to create an all in one menu driven program using C or C++ graphics programming language. Here, I have built the menu driven program in the Turbo C++ IDE using graphics.h library.

About the program :

This is a simple menu driven graphics program where you can calculate various mathematical and logical operations based on user input through a menu system. When you run the program, you will see a menu with various options for mathematical and logical operations. Now you have to enter a choice. According to your input, the program executes the corresponding operation.

In the program, you can perform addition, subtraction, multiplication and division of numbers. Here, you also see a calculator option in the program. You can also calculate various tasks such as simple interest, gross salary, distance conversion, total marks and percentage, temperature conversion and more.

After completing an operation, the program asks you to press any key to display the menu again. When you enter an incorrect choice, you can hear an alert sound. To stop the program, you have to enter “0”.

Explanation of the program :

At first, include header files such as graphics.h, stdlib.h, stdio.h, conio.h, dos.h and math.h in the program. In the main function, declare different types of various variables. Using initgraph() function initialize the graphics system with “graphic_driver” and “graphic_mode”. Now, set the background and foreground colors using setbkcolor() and setcolor() functions respectively.

In the infinite while loop, display a menu with options for various mathematical and logical operations using printf() function. Now, you can take the user choice as input by scanf() function. Then clear the screen using system() function. After that, you can use a switch case statement to execute different operations based on the input of the user.

In the switch case statement, your choice must be 0 to 22. Otherwise, your input will be wrong. When you enter your choice, the switch case statement performs appropriate task according to your choice. If you enter “0”, the program will be stopped because using “goto last” exit the infinite loop and close the graphics system by closegraph() function. When you enter 1 to 22 as choice, you can calculate different task according to your choice.

If you enter wrong or invalid choice (except 0 to 22), the program produces an error sound using sound() and nosound() function.

How run the program :

To run the program on your pc, you have to install the Turbo C++ IDE. After that, create a C or C++ file in the Turbo C++ IDE with .c or .cpp extension. Now, copy the following source code of menu driven program and paste in the C or C++ file. Do you know how to copy paste in the Turbo C++ IDE? You can also know how to use graphics.h in Turbo C++ IDE from here.

Source code :

The following code is the source code of the menu driven program in C or C++ programming language.

Output :

You can see the output of a menu driven program like below image.

output of the menu driven program in C or C++ programming language

Conclusion :

This is a basic menu driven program in C or C++ programming language. After completing the article, you can create your own menu driven program by adding more features based on your specific requirements. Thanks you for visiting my site.

Scroll to Top