Jump to content

Welcome to Geeks to Go - Register now for FREE

Geeks To Go is a helpful hub, where thousands of volunteer geeks quickly serve friendly answers and support. Check out the forums and get free advice from the experts. Register now to gain access to all of our features, it's FREE and only takes one minute. Once registered and logged in, you will be able to create topics, post replies to existing threads, give reputation to your fellow members, get your own private messenger, post status updates, manage your profile and so much more.

Create Account How it Works
Photo

C++ Sorting


  • Please log in to reply

#1
ihatetheworld

ihatetheworld

    New Member

  • Member
  • Pip
  • 6 posts
this is a program that takes test scores from a user adds them up to get the average then displays the test scores in an asending order with the bubble sort. i have the code but i am at a loss if it is right and how to display it. sorry i am new to programing....

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

#include
#include
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];
}

//bubble sort
for (int i=0; i
for (int j=i; 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;
}
  • 0

Advertisements


#2
gust0208

gust0208

    Member

  • Member
  • PipPipPip
  • 311 posts
I was a bit confused by your question and some of the code you posted appears to have been truncated (the for loops) and if you use the [code=auto:0] tags, it makes it much easier to read. What exact display problems are you having? Is it displaying the now sorted scores? Give us a bit more info and we can hopefully help.

Cheers,
Tom
  • 0






Similar Topics

0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users

As Featured On:

Microsoft Yahoo BBC MSN PC Magazine Washington Post HP