Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <ol> <li>In <code>void input()</code>, there should no <code>i++</code> out of <code>for</code> ?And <code>i</code> should start from 0?</li> <li>The fatal error in <code>void convert()</code> <code>for( int i = 1; i&lt;= n; i++ )</code>. since you define words as <code>string[5]</code>, it should start from <code>words[0]</code> to <code>words[4]</code>. So is <code>nums[5]</code>.</li> </ol> <p>Correction code:</p> <pre><code>#include &lt;iostream&gt; #include &lt;algorithm&gt; #include &lt;string&gt; #define n 5 using namespace std; string words[n] = {}; int nums[n]; void input(){ cout&lt;&lt;"Enter in word form, the numbers to be sorted\n"; for( int i = 0; i&lt;n ; i++){ cin &gt;&gt; words[i]; if( words[i] == "nil" ) break; //i++; } } void convert(){ cout&lt;&lt;"n = "&lt;&lt;n&lt;&lt;endl; for( int i = 0; i&lt;n; i++ ){ if ( words[i] == "one" ) nums[i] = 1; else if ( words[i] == "two") nums[i] = 2; else if ( words[i] == "three") nums[i] = 3; else if ( words[i] == "four") nums[i] = 4; else if ( words[i] == "five") nums[i] = 5; else if ( words[i] == "six") nums[i] = 6; else if ( words[i] == "seven") nums[i] = 7; else if ( words[i] == "eight") nums[i] = 8; else if ( words[i] == "nine") nums[i] = 9; else if ( words[i] == "zero") nums[i] = 0; else cout&lt;&lt;"Wrong input\n"; } } void sort(){ sort(nums, nums + n); for ( int i = 0; i &lt; n; i++ ) cout&lt;&lt; nums[i]&lt;&lt;endl; } int main(){ input(); cout &lt;&lt;"after input" &lt;&lt;endl; convert(); cout &lt;&lt;"after convert" &lt;&lt;endl; sort(); system("pause"); return 0; } </code></pre>
    singulars
    1. This table or related slice is empty.
    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.
    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