Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/cplusplus/145.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C++ 如果布尔是真的,我应该把它放在哪里_C++ - Fatal编程技术网

C++ 如果布尔是真的,我应该把它放在哪里

C++ 如果布尔是真的,我应该把它放在哪里,c++,C++,我编写了一个程序,该程序输出的名称相当于用户写入控制台的数字等级 1.失败 2.令人满意 3.做好人 4非常好 五是优秀 现在我想问用户,在第一次运行之后,他是否想继续输入成绩 e、 g 输入等级 -> 5 杰出的 您想继续输入成绩吗?1-是/0-否 如果布尔是真的,我就不知道该怎么办 int main() { int grade; do { cout << "input your grade: \n";

我编写了一个程序,该程序输出的名称相当于用户写入控制台的数字等级

1.失败

2.令人满意

3.做好人

4非常好

五是优秀

现在我想问用户,在第一次运行之后,他是否想继续输入成绩

e、 g

输入等级 -> 5 杰出的 您想继续输入成绩吗?1-是/0-否

如果布尔是真的,我就不知道该怎么办

int main()
{
    int grade;


        do
        {
            cout << "input your grade: \n";
            cin >> grade;

            if (grade < 1 || grade > 5)
            {
                cout << "input grade again!\n";
            }



        } while (grade < 1 || grade > 5);



        switch (grade)
        {
        case 1:
            cout << "fail\n";
            break;

        case 2:
            cout << "satisfactory\n";
            break;

        case 3:
            cout << "good\n";
            break;

        case 4:
            cout << "very good\n";
            break;

        case 5:
            cout << "excellent\n";
            break;



        }

    return 0;
}
intmain()
{
国际等级;
做
{
cout>等级;
如果(等级<1 | |等级>5)
{
cout(5);
道岔(坡度)
{
案例1:

cout您只需要另一个do while语句就可以进行重复处理。我已经初始化了一个名为
userChoice
char
变量(始终进行初始化以避免未定义的行为和难以跟踪的错误),以检查每个迭代中用户想要的内容(继续或结束程序)

//以前的代码。。。
char userChoice='n';
做{
//要重复的先前代码
std::cout>userChoice;//将用户的输入存储在userChoice变量中
}while(userChoice);//如果用户的输入为“y”,则继续下一次迭代
//代码的其余部分。。。
而且

//previous codes...
char userChoice = 'n';
do{
    // previous codes which you want to be repeated
    std::cout << "\nDo you want to continue ? (y = Yes, n = No ) "; // ask the user to continue or to end
    std::cin >> userChoice; // store user's input in the userChoice variable

}while(userChoice); // if user's input is 'y' then continue with next iteration
//rest of the code...