c++ - 为什么我的程序不会重新进入我的第二个 while 循环? C++

标签 c++

<分区>

我对数组的所有命令和更改都是单独工作的。但是,当我尝试返回菜单时,屏幕开始抖动并且不会继续。我被迫关闭程序。我该如何解决这个问题。

/* Programmer: Joshua Zuber
   Program Desc: This Program will allow the user to select an icon to display around an array message!
   Program Name:  Array Demonstration
   Clean Compile Date: 
*/

#include<iostream>
#include<string>
#include<iomanip>
#include<cstdlib>
#include<ctime>

using namespace std;

int main()
{
    // Arrays
    string Masterfile[] = "I want to thank all the C++ students who has helped me this semester. You have inspired me to work harder and to be able to design small C++ programs using a gamming approach. ";
    string Studentfile[]= "";


    // Variables
    int Icon;
    char again = 'y';
    int i;
    int j;
    int menu = 'y';
    int menu2 = 'n';
    int menu3 = 'n';
    int menu4 = 'n';
    int menu5 = 'n';
    int objEdit;

    while (toupper(again) == 'Y') // Start Main Loop
        {
            cout << "Welcome to Array Demonstration!" << "\n\n";
            cout << Masterfile[0] << "\n\n";

            while(toupper(menu) == 'Y' || toupper(menu2) == 'Y' || toupper(menu3) == 'Y' || toupper(menu4) == 'Y' || toupper(menu5) == 'Y' ) // Start Array Menu Loop
                {
                    cout << "Please select one of the below options to edit this string!" << "\n\n";
                    Studentfile[0] = Masterfile[0];
                    cout << "1. Size" << "\n\n";
                    cout << "2. Replace {all of the C++ students} with {My instructer, Professor Penn}" << "\n\n";
                    cout << "3. Swap the word {small} with {efficient}" << "\n\n";
                    cout << "4. Erase the phrase {using a gamming approach}" << "\n\n";
                    cout << "5. View Final Product" << "\n\n";
                    cin >> objEdit;

                    if(objEdit == 1) // Menu Array Size Check
                        {
                            cout << "The size of the original string is: " << Masterfile[0].size() << "\n\n";
                            cout << "\n\n" << "Would you like to return to menu? Y/N " << "\n\n";
                            cin >> menu2 ; 
                            system("cls");
                        }
                    else if(objEdit == 2) // Menu 2nd Option
                        {
                            cout << "Changing the phrases!" << "\n\n";
                            Studentfile[0].replace(16,20,"My instructer, Professor Penn"); 
                            cout << Studentfile[0] << "\n\n";
                            cout << "\n\n" << "Would you like to return to menu? Y/N " << "\n\n";
                            cin >> menu3; 
                            system("cls");
                        }
                    else if(objEdit == 3) // Menu 3rd Option
                        {
                            cout << "Changing the phrases!" << "\n\n";
                            Studentfile[0].replace(131,5,"efficient" ); 
                            cout << Studentfile[0] << "\n\n";
                            cout << "\n\n" << "Would you like to return to menu? Y/N " << "\n\n";
                            cin >> menu4; 
                            system("cls");
                        }
                    else if(objEdit == 4) // Menu 3rd Option
                        {
                            cout << "Changing the phrases!" << "\n\n";
                            Studentfile[0].erase(150); 
                            cout << Studentfile[0] << "\n\n";
                            cout << "\n\n" << "Would you like to return to menu? Y/N " << "\n\n";
                            cin >> menu5; 
                            system("cls");
                        }
                    else if (objEdit <=0 || objEdit >=6) // Menu Failsafe
                        {
                            cout << "Please Select a Valid Number" << "\n\n";
                            cout << "1. Size" << "\n\n";
                            cout << "2. Replace {all of the C++ students} with {My instructer, Professor Penn}" << "\n\n";
                            cout << "3. Swap the word {small} with {efficient}" << "\n\n";
                            cout << "4. Erase the phrase {using a gamming approach}" << "\n\n";
                            cout << "5. View Final Product" << "\n\n";
                            cin >> objEdit;
                        } 

                    else if(objEdit == 5 || toupper(menu) == 'N') // Menu 5th Option
                        {
                            cout << "Please Select one of the following numbers to choose a symbol!" << "\n\n";
                            cout << "1. *" << "\n\n";
                            cout << "2. ^" << "\n\n";
                            cout << "3. #" << "\n\n";
                            cout << "4. +" << "\n\n";
                            cin >> Icon;
                            system("cls");

                            if(Icon <= 0, Icon >= 5)  // User Failsafe
                                {
                                    cout << "You're Entry Is Not Valid" << "\n\n";
                                    cout << "Please Select one of the following numbers to choose a symbol!" << "\n\n";
                                    cout << "1. *" << "\n\n";
                                    cout << "2. ^" << "\n\n";
                                    cout << "3. #" << "\n\n";
                                    cout << "4. +" << "\n\n";
                                    cin >> Icon;
                                    system("cls");
                                }
                            else // Icon Breakdown
                                {

                                    if(Icon == 1) //  Icon Choice 1
                                        {
                                            for (i=1;i<=1;i++)
                                                {
                                                    for (j=1;j<=i;j++);
                                                    {
                                                        cout << "*******************************************************************************" << "\n";
                                                        cout << Studentfile[0] << "\n";
                                                        cout << "*******************************************************************************" << "\n";
                                                        cout << endl;
                                                        cout << "\n\n" << "Do you wish to play again? Y/N " << "\n\n";
                                                        cin >> again; 
                                                        system("cls");
                                                    }
                                                }
                                        }

                                    else if(Icon == 2) // Icon Choice 2
                                        {
                                            for (i=1;i<=1;i++)
                                                {
                                                    for (j=1;j<=i;j++);
                                                    {
                                                        cout << "^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^" << "\n";
                                                        cout << Studentfile[0] << "\n";
                                                        cout << "^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^" << "\n";
                                                        cout << endl;
                                                        cout << "\n\n" << "Do you wish to play again? Y/N " << "\n\n";
                                                        cin >> again; 
                                                        system("cls");
                                                    }
                                                }
                                        }

                                    else if(Icon == 3) // Icon Choice 3
                                        {
                                            for (i=1;i<=1;i++)
                                                {
                                                    for (j=1;j<=i;j++);
                                                    {
                                                        cout << "###############################################################################" << "\n";
                                                        cout << Studentfile[0] << "\n";
                                                        cout << "###############################################################################" << "\n";
                                                        cout << endl;
                                                        cout << "\n\n" << "Do you wish to play again? Y/N " << "\n\n";
                                                        cin >> again; 
                                                        system("cls");
                                                    }
                                                }
                                        }
                                    else if(Icon == 4) // Icon Choice 4
                                        {
                                            for (i=1;i<=1;i++)
                                                {
                                                    for (j=1;j<=i;j++);
                                                    {
                                                        cout << "+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++" << "\n";
                                                        cout << Studentfile[0] << "\n";
                                                        cout << "+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++" << "\n";
                                                        cout << endl;
                                                        cout << "\n\n" << "Do you wish to play again? Y/N " << "\n\n";
                                                        cin >> again;
                                                        system("cls");
                                                    }
                                                }
                                        }
                                    else   //  Icon Choice 5
                                        {
                                            cout << "Sorry You Didn't Want to Play" << "\n\n";
                                            cout << "\n\n" << "Do you wish to play again? Y/N " << "\n\n";
                                            cin >> again; 
                                            system("cls");  
                                        }
                                }
                        }              
                } // End Menu Loop   
        }   // End Main Loop        
    cout << "Thank you for playing!" << "\n\n";
    system("pause");
    return 0;   
}

最佳答案

可能是因为您将 menu .. menu5 定义为 int。尝试:

char menu = 'y';
char menu2 = 'n';
char menu3 = 'n';
char menu4 = 'n';
char menu5 = 'n';
....

关于c++ - 为什么我的程序不会重新进入我的第二个 while 循环? C++,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42347837/

相关文章:

c++ - 用空格拆分字符串但只得到第一个字

c++ - 如何跨平台使用Poco C++库的FIPS模式?

c++ - 使编译器在类型删除中使用 lambda 优化函数调用间接

c++ - 使用 C++0x std::thread 在 new-ed 对象中调用成员函数

c++ - R 调用 Cpp 代码 : global variables not re-initialized

c++ - QWebView 在 Ubuntu 13.10 上不工作

c++ - 从 QTreeView 中的 QModelIndex 获取平行索引

c++ - 使用 getch() 保持命令提示符打开 Visual C++ 2010

用于多次搜索的 C++ 最快的数据结构

c++ - 重新声明 C++ 内置类型 'wchar_t' windows 10 glut cpp