Outputting an Array of 5 Numbers in Order
Hi,
Simple question. Say you want to output an array of 5 numbers in order, with the highest first. Would the following be an efficient way to do it, or are there ways to do this better?
Thanks.
Code:
#include <iostream>
using namespace std;
int main()
{
int tempscore, b;
int tempscore2 = 999;
int a = 0;
int scores[5] = {33, 99, 74, 89, 12};
while (a < 5)
{
tempscore = -999;
for (b = 0; b < 5; b++)
if ((scores[b] > tempscore) && (scores[b] < tempscore2))
tempscore = scores[b];
for (b = 0; b < 5; b++)
if (scores[b] == tempscore)
{
cout << scores[b] << " ";
a++;
}
tempscore2 = tempscore;
}
}