Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>I've corrected your code. Try something like this</p> <pre><code>#include &lt;iostream&gt; #include &lt;string&gt; using namespace std; int main () { int score[100], score1 = -1; char word[100][100]; do { score1++; cout &lt;&lt; "Please enter a score (-1 to stop): "; cin &gt;&gt; score[score1]; } while (score[score1] != -1); cin.ignore(); for (int x = 0; x &lt; score1; x++) { cout &lt;&lt; "Enter a string: "; cin.getline(word[x], 100); } for (int x = 0; x &lt; score1; x++) { cout &lt;&lt; score[x] &lt;&lt; "::" &lt;&lt; word[x] &lt;&lt; endl; // need output to be 88:: hello there. } } </code></pre> <p>OK what have I done? First of all I delete extra <em>{</em>. When I've seen your code for the first time I have no idea if there is do..while loop or while loop in do.while. Next I change string array to char array, just because I know how to read line to char array. When I need to read line to string I always use my own function, but if you really want to use string <a href="https://stackoverflow.com/a/5059112/1387612">here</a> is great example. Rest is quite obvious. <em>cin.ignore()</em> is required because new line character stays in buffer so we need to omit it. </p> <p><strong>EDIT:</strong> I've just found better way to fix your code. Everything is OK but you need to move <em>cin.ignore()</em> and place it just after <em>while (score[score1] != -1);</em>. Because wright now you are ignoring first char of every line and you need only ignore new line after user type -1. <a href="http://ideone.com/E6JQx" rel="nofollow noreferrer">Fixed code.</a></p>
    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.
    1. This table or related slice is empty.
    1. VO
      singulars
      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