sorting


Read With Formatting | Free Open Source Tutorials Account

C and C++ Programming
Thread: sorting


ledzep
how would i got about displaying my sorted numbers, thanks

// This program Enter test scores and sort them in oder and Averages them

#include <iostream>
#include <iomanip>
using namespace std;

int main()
{
double *score, total = 0, average;
int TestScores, count;


cout << "How many Test Scroes do you wish to enter ";
cin >> TestScores;
score = new double[TestScores]; // Allocate memory

// Get the Test Scores
cout << "Enter each students test scores.\n";
for (count = 0; count < TestScores; count++)
{
cout << "Student " << (count + 1) << ": ";
cin >> score[count];
}


for (int i=0; i<TestScores; ++i)
for (int j=i; j<TestScores; ++j)
if (score[i] < score[j])
{
double tmpscore = score[i];
score[i] = score[j];
score[j] = tmpscore;
}


// Calculate the total Scores
for (count = 0; count < TestScores; count++)
{
total += score[count];
}

// Calculate the average Test Scores
average = total / TestScores;

// Display the results
cout << fixed << showpoint << setprecision(2);

cout << "Average Score: " << average << endl;


// Free dynamically allocated memory
delete [] score;

return 0;
}

humptydumpty
So Dude Actually What's The problem you are Getting here.mean to say in case of Sorting. and Will Suggest you Before Writing a Program on your PC better Dry Run your Program and Check it out.if Still Problem Please let us Know.
Thanx