Q1: Why does count_scores() not print the amount of each number in the array? for ( i=0; i < 11; ++i) cout << i << "'s is: " << count << endl; Q2: How do I insert " - - " or spaces under the values that have been swapped? The for (k=0; k<10 ; ++k) just prints a column of "_ _" Q3: How does the error_flag work? Q4: Why does my sort function not underline the values that are swapped?
Q1: Why does count_scores() not print the amount of each number in the array? for ( i=0; i<11; ++i) cout << i << "'s is: " << count << endl; A1: Looks like you are telling your program to print out the indices, i, (subscript) NOT the value of the array, count[i]. Also, "count" is the name of array (base address of the array) "count[i]" are the values. AND your count[] array is still filled with zeroes. It tallie (sums) the quiz scores into the individual MATCHING elements.
Q2: How do I insert " - - " or spaces under the values that have been swapped? The for (k=0; k<10 ; ++k) just prints a column of "_ _" A2: swap (a[i],a[j]); // Look at this line for "if" hints for (k=0; k<10 ; ++k) // Yes use this Either // if print "_ _" // NOT a column (no newline) OR print " "
Q3: How does the error_flag work? A3: Pseudo code from blackboard. Comments added for answer A3. error_flag = 0 // Clear error flag to 0 (false) do { cout<<" Enter 10 quiz scores: "; // Prompt for 10 ints in range (0-10) for ( . . . ; . . .; . . . ) // Loop index 0 -10 cin>> scores[i]; // Read in scores[0] - scores[9] if ( ... < ... > 10 ); // If out of range { cout<<"Error reenter scores.\n"; // Print error message error_flag = 1; // Set error flag to true } } while (error_flag) // If one of the numbers entered set the flag to true // Then read in 10 numbers again Pretend we don't have an error flag. Then how do we remember to read in all 10 numbers again? The only way is to test in the do while loop and it would be able to hold onto ONLY the last element in the array to test if we need to reloop and read all 10 numbers AGAIN.
Q4: Why does my function not underline the values that are swapped? > if (a[i]>a[j]) > { > swap (a[i],a[j]); > for (k=0; k if (a[i] > a[j]) // WHAT??? this is already TRUE, look at > // this "if" THINK AGAIN !! A4: Look at your if else for the 2 cout statements. a[0] a[1] a[2] 3 2 1 2 3 1 // swap a[0] > a[1], swap( a[i], a[j]) ); ---- ---- // for (k = 0; k < 3 ; ++k ) if ( k ) cout --- else cout " "

HOME || Course Description || Course Outline || Lab Hours || FAQ || Midterm || Final