Структура меню и циклы

0

У меня есть небольшая программа, которую я создаю. В терминах ламы я хочу создать меню, в котором пользователь может ввести свой выбор, он доставит его до заданной области, и после того, как он закончит, он вернет его в меню, где он может сделать другой выбор. Я спустился туда, где он отображается, когда вы нажимаете 1 (вы увидите, что я имею в виду с кодом). Но после того, как он проходит через то, что он должен делать, он не возвращается в меню, он просто переходит к второму варианту. Также скажите, что вы находитесь в меню, и вы хотите начать со второго варианта, который только начинается с первого. Может кто-нибудь, пожалуйста, помогите мне с этим...

#include <iostream>

using namespace std;

int main()
{
int option;

    cout << "Hello there...\n\nToday we are going to do a little fun project that I created.\n\n";
    cin.get();

    cout << "\nAs we progress throughout this program, I will explain the different things\n";
    cout << "that we are going to do. We will be covering some basic C++ excersises.";
    cout << "\n\nFirst and foremost we will  begin by  covering what I have learned so far....\n\n";
    cin.get();

    cout << "The first topic we will cover will include what is known as 'variables'.\n";
    cout << "what are variables you ask?";
    cin.get();


    int var = 1;
    int main=1;
        do
        {
            cout << "\n\n\nEnter the number of one of the following and I will explain!\n";
            cout << "1.integer  2.boolian   3.floats   4.doubles   5.character";
            cout << "\n\n[when you are done type 'done' to continue]\n\n";
            cin >> option; //this is where the user puts in his option (1,2,3,4,5,6) I have only 1 and 2 complete

            if (option = 1) //starts with this regardless of input
            {
                cin.ignore();
                cout << "\n\n\nInteger is the variable abbreviated as 'int' this allows C++ to only";
                cout << "\nread whole and real numbers. C++ takes this number as stores it\n";
                cout << "in a user-defined variable (you can make up what that variable is..)\n";
                cin.get();
                cout << "an example syntax would be:";
                cout << "\n\nint var=[whole;real number]";
                cin.get();
                cout << "\n\nwhat this implies is that you have 'declared' to the system";
                cout << "\nthat you are going to use an 'int' that you have named 'var'\n";
                cout << "and in this 'var' you are going to store a real and whole number\ninside of it.";
                cout << "\n\nPress any key to go back to menu";
                cin.get();
            }
            else if (option = 2); //continues with this without going back to menu.
            {
                cin.ignore();
                cout << "\n\n\nBoolian is the variable abbreviated as 'bool' this allows C++ to only";
                cout << "\nread true or false ( 0 or 1 ). C++ takes this number as stores it\n";
                cout << "in a user-defined variable (you can make up what that variable is..)\n";
                cin.get();
                cout << "an example syntax would be:";
                cout << "\n\nbool var=[true or false]";
                cin.get();
                cout << "\n\nwhat this implies is that you have 'declared' to the system";
                cout << "\nthat you are going to use an 'bool' variable that you have named 'var'\n";
                cout << "and in this 'var' you are going to store a either a true or false\ninside of it.";
                cout << "\n\nPress any key to go back to menu";
                cin.get();
            }

        } while (var = 1);

}

Теги:

2 ответа

1

Проблема заключается в том, что оператор сравнения

1) if (option = 1), используйте if(option == 1)

2) else if (option = 2); , используйте else if(option == 2), удалите точку с запятой

3) while(var = 1) ; , используйте while(var ==1 );

0

сравнение в C++ выполняется с помощью оператора:

например

 if (option == 1) 
 if (option == 2) 
 while (var == 1);

Ещё вопросы

Сообщество Overcoder
Наверх
Меню