Search code examples
c++bubble-sort

how to exit upon entering negative number


This program asks for 100 inputs and sorts inputs in ascending order also calculates the average of all the inputs. I am wondering how do i make it to exit upon entering negative number instead of asking for 100 inputs, and show average .

solved!


Solution

  • Try This In Your Code in for loop

    cin >> temp;
    if(temp >= 0)
        anArray[count] = temp;
    else
    {
    
        scores = count;
        break;
    }