-1终止但仍显示摘要

时间:2013-11-10 22:23:21

标签: c++ termination

我需要这样做,所以-1将在第十个结果之前终止程序,但仍然显示摘要。每次我让它工作它只是停止和结束,但不会向我显示摘要。

6个结果摘要的示例输出,但我不能让它在6处停止并在输入-1时显示摘要我应该放置哪些想法? 结果1 10.00 U级 结果2 20.00 U级 结果3 30.00 U级 结果4 40.00 U级 结果5 50.00等级P. 结果6 70.00 C级

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 个答案:

答案 0 :(得分:0)

在循环块后打印夏季之前,只需输入此代码:

if (!test)
  return 0; // if you're in the main, or exit(0);