通过-1终止的问题 [英] issue with terminating through -1

查看:131
本文介绍了通过-1终止的问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要使用-1来终止,但仍然显示摘要。
每次我试过,并得到它终止程序,它不会继续前进并显示摘要。
有10个试验,如果你没有足够的信息10,你想停止在8,你输入-1,它去到摘要,然后终止程序

I need to use -1 to terminate but still display the summary. Every time that I've tried and have gotten it to terminate the program, it doesn't go ahead and display the summary. There are up to 10 trials, if you don't have enough information for 10 and you want to stop at 8, you type -1 and it goes to the summary and then terminates the program


while(i<10)
{
    do
    {
    cout << "Enter result """ << i+1 << """ (or -1 if no more results): ";
    cin >> score[i];
    if(score[i] >=0 && score[i] <=49)
    {
        cout << "Grade " << "U" << " will be assigned to this result\n";
        bool test=true;
        i++;
    }
    else if(score[i] >=50&& score[i] <=59)
    {
        cout << "Grade " << "P" << " will be assigned to this result\n";
        bool test=true;
        i++;
    }
    else if(score[i] >=60 && score[i] <=69)
    {
        cout << "Grade " << "C" << " will be assigned to this result\n";
        bool test=true;
        i++;
    }
    else if(score[i] >=70 && score[i] <=89)
    {
        cout << "Grade " << "B" << " will be assigned to this result\n";
        bool test=true;
        i++;
    }
    else if(score[i] >=90 && score[i] <=100)
    {
        cout << "Grade " << "A" << " will be assigned to this result\n";
        bool test=true;
        i++;
    }




    else
    {
        test=false;
        cout << "Invalid Input!\n";
    }
    }
    while(test);
}



cout << "\nSummary of the results:\n";
for(int a=0;a< 10;a++)
{
std::cout <<  std::fixed << std::setprecision(2) << "Result " << a+1 << " "  << score[a] << " Grade " << determine_grade(score[a]) << "\n";
}

cout << "\nThe average of the results = " << calc_average(score) << "\n";
cout << "The lowest of the results = " << find_lowest(score) << "\n";
cout << "The highest of the results = " << find_highest(score) << "\n";
system("Pause");


推荐答案

尝试使用 当-1被输入while循环时。另外,你可以使用1个循环,而不是上面提到的john的两个循环。

Try to use break; when -1 is inputted inside the while loop. Also, you can use 1 loop, instead of two as john mentioned above.

另一件要找的是你的最后一个for循环,它从0到9,如果有人使用-1并且只输入3个等级,则解决方案可能有奇数值。

Another thing to look for is your last for loop, it goes from 0 to 9, but in case someone used -1 and only inputted 3 grades, there might be odd values for the solutions.

这篇关于通过-1终止的问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆