0
#include <iostream>
#include <string>
#include <cmath>
#include <math.h>
#include <algorithm>
#include <cstdlib>

using namespace std;

int main()
{
    string names[10];
    int score[10];

    for(int scores = 0; scores < 10; scores++)
    {
        cout << "What is your score? ";
        cin >> score[scores];
        cout << endl;
    }


    int swapHolder = -1;
    int ten = 10;

    for(int counter = 9; counter >= 0; counter--)
    {
        for(int i = 0; i < 10; i++)
        {
            if(score[i] > score[i + 1])
            {
                swapHolder = score[i + 1];
                score[i + 1] = score[i];
                score[i] = swapHolder;
            }
        }
        ten--;
    }

    for(int i = 0; i < 10; i++)
    {
        cout << "Score: " << score[i] << endl;
    }

    system("pause");
    return 0;
}

How do I fix my Run time failure #2??

3
Contributors
2
Replies
4
Views
5 Years
Discussion Span
Last Post by deceptikon
0

You don't explain what you mean by "runtime failure #2". Are you running this as a managed c++ application in C#? How did you compile it? What operating system is it running on? What compiler did you use?

0

You're overrunning the end of the array in the sorting algorithm. The inner loop should stop at 8 rather than 9, because inside the loop you're referencing the index at i + 1.

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.