Sunday, July 12, 2009

Creating a simple menu in C++?

I want to create a very simple menu that one option to allow me to load a input file and another option to display the input file and the last option to quit the program.. Is there any resources that can help me with this?





I have this so far:





#include %26lt;iostream%26gt;


#include %26lt;fstream%26gt;


#include %26lt;iomanip%26gt;


#include %26lt;string%26gt;





using namespace std;





int main()


{


int l, d, q;


char ch;


ofstream outFile;


string outputFile;





cout %26lt;%26lt; "Menu" %26lt;%26lt; endl;


cout %26lt;%26lt; "L Load from file";


cin %26gt;%26gt; ch;


cout %26lt;%26lt; endl;





outFile.open("sample.txt", ios::out);}





I compile it successfully but running it was kinda messed up (figured that anyway since it's not completely done).

Creating a simple menu in C++?
it is an example of implementng menu urs dont has any menu concept.








#include%26lt;stdio.h%26gt;


#include%26lt;conio.h%26gt;





void main(void)


{


int num1, num2, operation, result;





clrscr();


printf("Enter a number: ");


scanf("%d", %26amp;num1);


printf("Enter a number: ");


scanf("%d", %26amp;num2);





printf("Indicate math operation\n[1:add; 2:sub; 3:mul; 4:div]: ");


scanf("%d", %26amp;operation);





switch(operation){


case 1:


result = num1 + num2;


break;


case 2:


result = num1 - num2;


break;


case 3:


result = num1 * num2;


break;


case 4:


result = num1 / num2;


break;


default:


result = 0;


}





printf("\nThe result is %d", result);


}


No comments:

Post a Comment