Jump to content

Welcome to Geeks to Go - Register now for FREE

Need help with your computer or device? Want to learn new tech skills? You're in the right place!
Geeks to Go is a friendly community of tech experts who can solve any problem you have. Just create a free account and post your question. Our volunteers will reply quickly and guide you through the steps. Don't let tech troubles stop you. Join Geeks to Go now and get the support you need!

How it Works Create Account
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