Okay i have tried everything please can someone help me i am trying to restart this program so i have used a do while loop. The problem is that when i say n to terminating it just asks the question again do i wish to terminate every time i click n

#include <iostream>

using namespace std;

int main ()
{
float total, score, average, minScore=6.0, maxScore=0.0, i;
int divers, judges;
int end;
char choice;


cout << "Enter the number of competetitors please: ";
cin >> divers;
cout << endl;
cout << "Scores input here\t\t\tAveraged scores displayed here\n\n";


do{

    while( divers > 0 ) {
           total=0.0;
           judges=1;
           score=0.0;

                   while( judges <= 5 ) {

                       cout << "Enter score: ";
                       cin >> score;
                       if (score>-0.1 && score<=6.0){
                                      total = total + score;
                                      judges = judges +1;

                                      if(score<minScore){
                                          minScore=score;}
                                      if(score>maxScore){
                                          maxScore=score;}
                                                  }else
                                          cout << "the score you entered is not valid please try again.\n";
                                          }
           i = i + maxScore + minScore;
           total = total - i;
           average = total / 3 ;
           cout << "Diver score is \t\t\t\t\t " << average << endl;

                          divers -= 1;
                          i=0.0;
                          judges=1;
                          minScore=6.0;
                          maxScore=0.0;
                          total=0.0;
                          }
          cout << "do you wish to terminate the program (y/n)?\n";
          cin >> choice;

          }while ((choice == 'N') || (choice == 'n'));

          cout << "goodbye!\n";

return 0;
}

Recommended Answers

All 4 Replies

21: while( divers > 0 ) { //You stop entering this loop after divers gets negative

41: divers -= 1;

You should change the condition at line 21

Because you click 'n', the choice is 'n' so the loop continues. Perhaps you should

do {
// the loop
} while(! (choice == 'N' || choice == 'n'))

Usually, I prompt "Do another? " and end if the lower case of the first character is not the initial for 'yes' in the current locale.

21: while( divers > 0 ) { //You stop entering this loop after divers gets negative

41: divers -= 1;

You should change the condition at line 21

any possibility of reinitializing divers to start the loop?

just figured it out i had to contain the first part of the code within the do while

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.