Question: My program will not compile after I reformatted it! Could you please help me to debug it? //Assignment 5.2 //Dar Sedigh #include #include using namespace
My program will not compile after I reformatted it! Could you please help me to debug it?
//Assignment 5.2 //Dar Sedigh #include
void initializeArrays(string names[], int scores[], int size) { for (int i = 0; i < size ; i++) {
cout << "Enter the name for score #"<< (i+1) << ": "; cin >> names[i]; cout << "Enter the score for score #"<< (i+1) << ": "; cin >> scores[i];
}
}
void sortData(string names[], int scores[], int size) {
// sort by scores for (int i = size; i >= 0; i--) {
for (int i = 0; i < size; i++) {
if(scores[i] < scores[i+1]) {
int tempscores = scores[i+1]; scores[i+1] = scores[i]; scores[i] = tempscores;
string tempnames = names[i+1]; names[i+1] = names[i]; names[i] = tempnames;
} } }
}
void displayData(const string names[], const int scores[], int size) {
cout << " Top Scorers: " << endl;
for (int i = 0; i < size; i++) {
cout << names[i] << ": " << scores[i] << endl;
}
}
int main() {
int *pointer = NULL;
//memory dynamic allocation pointer = new int;
//size of array is dynamic and is entered by user at console cout << "How many scores will you enter? "; cin >> *pointer; const int size = *pointer;
//declaration of array's names and scores & dynamic memory allocation using new keyword int *scores = 0; scores = new int[size]; string *names = new string[*pointer];
//Entry point of function's-> invoke three function here initializeArrays(names, scores, size); sortData(names, scores, size); displayData(names, scores, size);
//memory freed or deallocated using delete keyword delete [] scores;
//pointer changed to '0' scores = 0; }
/* output: How many scores will be entered? 4 Enter the name for score #1: Suzy Enter the score for score #1: 9900 Enter the name for score #2: Kim Enter the score for score #2: 1000000 Enter the name for score #3: Armado Enter the score for score #3: 822 Enter the name for score #4: Tim Enter the score for score #4: 514
Top Scorers: Kim: 1000000 Suzy: 9900 Armado: 822 Tim: 514 */
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
