Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Categories

sample program using nested statements

lanzlanz Member Posts: 11
Is there anyone who can give me a sample program that has 4 choices; and inside each of them (their sub-menus) there are also 3 choices. I need some ideas for my project (A menu-based program)... thanks!!!

Comments

  • thellmanthellman Member Posts: 62
    : Is there anyone who can give me a sample program that has 4 choices; and inside each of them (their sub-menus) there are also 3 choices. I need some ideas for my project (A menu-based program)... thanks!!!
    :

    [blue]
    This is one possibility to do this. Instead of swicth-case, you can also use if - else if - else, or just plain old ifs.
    [/blue]
    [code]
    #include

    int main()
    {
    char choice;

    // Get the first choice
    cout << "1)Choice 1" << endl;
    cout << "2)Choice 2" << endl;
    cout << "3)Choice 3" << endl;
    cout << "0)quit" << endl;
    cin >> choice;
    cout << "Choice was: " << choice << endl;
    switch ( choice )
    {
    case '1':
    {
    cout << "1)SubChoice 1" << endl;
    cout << "2)SubChoice 2" << endl;
    cout << "3)SubChoice 3" << endl;
    cin >> choice;
    // then do something with choice
    }
    case '2'
    {
    // In the same manner as 1
    }
    case '3'
    {
    // ....
    }
    case '0'
    {
    // ....
    }
    default:
    {
    cout << "Quitting" << endl;
    }
    }
    }
    [/code]
  • Geeth AsokanGeeth Asokan Member Posts: 127
    : Is there anyone who can give me a sample program that has 4 choices; and inside each of them (their sub-menus) there are also 3 choices. I need some ideas for my project (A menu-based program)... thanks!!!
    :

    Hi,

    To do the above, you could either accomplish this by using a 'switch' statement or an 'if - else' statement.

    G dunn!

  • Chris BrownChris Brown USAMember Posts: 4,624 ✭✭

    _________ / http://forcoder.org / free video tutorials and ebooks about [ PL/SQL, Scratch, Visual Basic .NET, Java, Swift, Python, C, Ruby, MATLAB, Delphi, C++, Objective-C, JavaScript, Assembly, R, Visual Basic, Go, C#, Perl, PHP COBOL, Prolog, ML, Rust, Hack, Clojure, Transact-SQL, Julia, LabVIEW, Lua, Crystal, Alice, Ada, F#, Awk, Bash, Apex, Lisp, SAS, Kotlin, D, Fortran, FoxPro, ABAP, VBScript, Scheme, Erlang, Scala, Dart, Logo ] ____

Sign In or Register to comment.