2013-11-10 3 views
-2

Мне нужно сделать так, чтобы -1 закончил программу до десятого результата, но все равно отображает сводку. Каждый раз, когда я получаю его на работу, он просто останавливается и заканчивается, но не покажет мне резюме.-1, чтобы завершить, но все же отобразить сводку

Пример вывода для итоговой работы 6 результатов, но я не могу заставить его остановиться на 6 и отобразить сводку, когда -1 вводится какие-либо идеи, где я должен ее разместить? Результат 1 10.00 Класс U Результат 2 20.00 Класс U Результат 3 30.00 Класс U Результат 4 40.00 Класс U Результат 5 50.00 Оценка Р Результат 6 70.00 Класс С

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"); 

ответ

0

Просто поставьте этот код перед печатью, после цикла цикла:

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