Note that there are some explanatory texts on larger screens.

plurals
  1. POSort input is working backwards
    primarykey
    data
    text
    <p>Ok, this was an assignment that I was deducted points due to the fact that the output was displayed backwards. I was supposed to prompt the user for input then display the input in descending order, but I am having an issue with the display. I have two arrays, one year[] to hold the months and one <code>month[totalMonths]</code> to hold the user input. When i sort and display the input the <code>year[]</code> does not correspond with the months, it is fixed. So for example if the user enters 1 for Jan, 2 for Feb and 3 for Mar, the display would be; Jan: 3 Feb: 2 Mar: 1</p> <p>Any ideas on how i can get the months to correspond with the its proper input for the display? Here is the sort and display function:</p> <pre><code>void sortArray(double month[], string year[], int totalMonths) { int temp; bool swap; do { swap = false; for(int count = 0; count &lt; totalMonths - 1; count++) { if(month[count] &lt; month[count + 1]) { temp = month[count]; month[count] = month[count + 1]; month[count + 1] = temp; swap = true; } } } while(swap); cout &lt;&lt; "------------------------------------------------------------" &lt;&lt; endl; cout &lt;&lt; "Here are the months rainfall statistics sorted from highest to lowest: " &lt;&lt; endl; for (int index = 0; index &lt; totalMonths; index++) cout &lt;&lt; year[index] &lt;&lt; "\t " &lt;&lt; setw(5) &lt;&lt; month[index] &lt;&lt; endl; } </code></pre> <p>Here is my <code>string year[]</code> definition:</p> <pre><code>string year[] = {"Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec"}; </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload