Monday, 10 November 2014

Create 'Menu' in Your Turbo C++ Program

My first question was how to create a menu in Turbo C++ which my friends failed to answers, even the ones who had special classes for this. I searched everywhere on the web and ended up with a script or I must say a program with menu. You will need to enter "1, 2, 3" or any other variable to open that certain part of this script. For example, if you press 1 in my old calculator TC++ program, then it will open addition window. If you press 2 it will open Subtraction window and so on. All you have to do is just copy your source code and paste it to my script which turns your program to a menu or multiple functioning script. So here's the source code for this. Please manually edit the script according to your needs: 


#include<conio.h>
#include<stdio.h>
#include<fstream.h>
#include<math.h>
#include<process.h>
void main()
{       clrscr();
unsigned int choice;
cout<<"\n\t\t\tYOUR TEXT WHICH WILL BE SHOWN IN THE MIDDLE OF THE SCREEN\n";
cout<<"\n\t\t\tPress 1 For ANYTHING\n";
cout<<"\n\t\t\tPress 2 For ANYTHING\n";
cout<<"\n\t\t\tPress 3 For ANYTHING\n";
cout<<"\n\t\t\tPress 4 For ANYTHING\n";
cout<<"\n\t\t\tPress 5 For ANYTHING\n";
                {       cout<<"";}
                cin>>choice;
                while(choice==1)
                {
----- Code if the person presses 1 and hit enter ------
                 }
                 while(choice==2)
                 {
          ----- Code if the person presses 2 and hit enter ------
                 }
                 if(choice==3)
                 {
----- Code if the person presses 3 and hit enter ------
                 }
                 if(choice==2)
                 {
----- Code if the person presses 4 and hit enter ------
                 }
 if(choice!=1&&choice!=2&&choice!=3&&choice!=4&&choice!=5)
                 {      cout<<"IF WRONG OPTION IS HIT, THEN THIS TEXT WILL DISPLAY.";
                        getch();
                        exit(0);
                 }
 if(choice==5)
 {
----- Code if the person presses 1 and hit enter ------
 }
        }
getch();

For example, have a look at my calculator having the same source code for the menu:




Get the script from my MediaFire account: http://goo.gl/JOItBq

1 comment:

  1. How to return back to the menu
    Since once i press one choice it carries on with tge same choice..
    For eg. If i press for addition it keeps on only adding

    ReplyDelete