Click here to Skip to main content
15,894,630 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
Just simply want to know how I can add an option to go back to the main menu after reading each sub-menu.

C++
#include <iostream>

using namespace std;


bool processMenu() {
    

	cout << "Main Menu" << endl;
	cout << "What would you like to read about?" << endl;
	cout << "1. Programming Paradigms" << endl;
	cout << "2. Different Programming languages, and their uses" << endl;
	cout << "3. Different C++ Features and their uses" << endl;


	char choice;
	cin >> choice;
	

	if (choice=='1') {
		cout << "A programming paradigm is a fundamental style of computer programming, serving as a way of building the structure and elements of computer programs. Imperative Paradigm: The language provides statements, such as assignment statements , which explicitly change the state of the memory of the computer. Functional: In this paradigm we express computations as the evaluation of mathematical functions. Logic: In this paradigm we express computation in exclusively in terms of mathematical logic. Object-Oriented: In this paradigm we associate behaviour with data-structures called objects which belong to classes which are usually structured into a hierarchy. " << endl;	
	} else if (choice=='2') {
		cout << "Java: Considered the perfect language for developers and programmers to learn. Most utilised for mobile based apps and for creating desktop applications. Python: Considered the simplest language to learn, Python is an extremely useful 'all in one' launguage. Used for anything from web animations to use interfaces. C and C#: C is a general-purpose, high-level language first implemented in 1972. It's easy to learn and handles low level activities well. C# is a highly expressive language, similar in structure to C++, C and even Java. Utilises many features not avilible in the Java language.  " << endl;
	} else if (choice=='3') {
		cout << "C++ can be used to develop new data types called 'classes'. By working with these 'classes', we can develop new libraries. Aswell as this, C++ provides templates and several templates and keywords not found in the C language, giving a wider range of useage. C++ has a huge function library and is a highly flexible language. Used for many, many things, including system software, operating systems, compilers, editors and data bases. " << endl;
	} else {
	    
		return false;
	}
	return true;
}

int main () {


    while (!processMenu()) {


    }

    cout << endl << "Thank you for Reading." << endl;

    return 0;

}
Posted
Updated 18-Nov-15 13:23pm
v3
Comments
Sergey Alexandrovich Kryukov 18-Nov-15 17:22pm    
"Just simply want to know..." are usually the most unpleasant questions taking infinite amount of time to answer. It's not "just". The whole idea is bad. Anyway, there is no such concept as "return to menu". And this is not a "real" menu, this is just the text explaining the options. The simplest approach is: output menu again after each action.
—SA
Mohibur Rashid 18-Nov-15 19:27pm    
change
while (!processMenu()) {


}
to
while (processMenu()) {


}
Statement below will work same.
while (processMenu());

And also try to understand Sergey Alexandrovich Kryukov's suggestion

1 solution

Please see my comment to the question.

This is not a "real" menu, this is just the text explaining the options. There is no such concept as "return" to it. The simplest approach is: output menu again after each action. First of all, break your code in smaller units, functions and possibly into classes/structs (you are writing about C++, so are you going to use C++ yourself? :-)); "showOptions" could be one of them. And call it again and again. Don't go into further complexity; it you need more advanced UI, make it Graphical UI.

But even this is not the best thing. Most console-only utilities are not interactive at all, they take all output from the command line. This way, the commands can be written in a batch file, edited and used again, and so on. Using interactive UI in a console-only application is way too awkward and inconvenient to the users. There is a small number of exceptions: system applications working as fully-fledged command interpreters, but I'm not sure it can make any sense, especially for you. Even the best of such applications present infinite source of confusion; say, CMD.EXE is often badly misused. Honestly, opt for pure command-line input.

And finally, how can you send to your cout so many false and incompetent statements about programming? Poor cout might get red. :-)

—SA
 
Share this answer
 
v4
Comments
Patrice T 18-Nov-15 17:44pm    
+5
Sergey Alexandrovich Kryukov 18-Nov-15 17:45pm    
Thank you.
—SA
Member 12150856 18-Nov-15 18:28pm    
No idea what you just said, but I thank you for your input, nonetheless.
George Jonsson 18-Nov-15 19:42pm    
You should check with Bjarne about C++ http://www.stroustrup.com/[^]
And for Object Oriented Programming in general, maybe this can be a start: https://en.wikipedia.org/wiki/Object-oriented_programming[^]
Sergey Alexandrovich Kryukov 18-Nov-15 23:51pm    
Good idea. And the inquirer can ask some follow-up questions, after all. This matter is not so complicated.
—SA

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900