C ++帮助返回上一级菜单

时间:2015-11-18 22:21:01

标签: 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;

}

1 个答案:

答案 0 :(得分:0)

试试这个:

#include<string.h>
#include<stdlib.h>
#include<stdio.h>
#include"stdafx.h"
#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() {
    int check = 0;
    while (check == 0)
    {

    while (!processMenu()) 
    {
    }

        cout << endl << "Thank you for Reading." << endl;
        cout << endl << "0 for yes." << endl;
        cout << endl << "Any other number for no." << endl;
        cout << endl;
        cin >> check;
    }
    cout << endl << "Thank you for Reading." << endl;
    return 0;

}

使用此代码,用户可以选择返回主菜单并阅读其他内容!