hello all! i seem to have a problem. i am assigned to display 50 test scores in rows of 5. I have no idea what i am doing, i have found nothing useful on the interwebs on how to display in rows and cols. So i come to you guys! :D
line 48 is where it stars, i had just run it through a bubblesort to arrange in ascending order, i just need them to print out in rows of 5.
#include <iostream>
#include <iomanip>
usingnamespace std;
void bubbleSort(double scores[], int numScores);
int main (void){
double *scores, //To dynamically allocate an array
total = 0, // Accumulator
average; // To hold average scores
int numScores, //To hold the number of test scores
count; //Counter variable
int row, col;
//Get the number of test scores
cout << "How many test scores would you like to enter? ";
cin >> numScores;
//Dynamically allocate an array large enough to hold that many test scores
scores = newdouble[numScores];
//Get the test scores
cout << "Enter the test scores below.\n";
for (count = 0; count < numScores; count++){
cout << "Test Score " << (count + 1) << ": ";
cin >> scores[count];
}
//Calculate the total of the scores
for (count = 0; count < numScores; count++){
total += scores[count];
}
//Calculate the average test score
average = total / numScores;
//Display the results
cout << fixed << showpoint << setprecision(2);
cout << "Average score is: " << average << endl;
//find min and max.
cout<<"Smallest grade:"<<*min_element(scores,scores+5)<<endl;
cout<<"Highest grade:"<< *max_element(scores,scores+5)<<endl;
bubbleSort(scores,numScores);
for (count = 0; count < numScores; count++){
for(row=0; row<5; row++)
{
cout<<row<<' ';
for(col=0; col<10; col++){
cout<<col;
}
}
//cout<<scores[count]<<endl;
}
//Free dynamically allocated memory
delete [] scores;
scores = 0; //Make scores point to null.
cin.ignore(INT_MAX, '\n');
cin.ignore(INT_MAX, '\n');
return 0;
}
void bubbleSort(double scores[], int numScores){
bool exchanges;
do{
exchanges = false; // assume no exchanges
for(int i = 0; i < numScores - 1; i++){
if(scores[i] > scores[i + 1]){
double temp = scores[i];
scores[i] = scores[i+1];
scores[i+1] = temp;
exchanges = true; // after exchange, must look again
}
}
}while(exchanges);
}
You should just be able to eliminate the two dimensional array you created using nested for loops and replace it with the for loop above with that 'if' starement . If there are 50 test scores being held in an array.. I had a similar problem, but mine had to generate 50 random numbers.
I created a display function. Passed in the array and used that approach above.