Note that there are some explanatory texts on larger screens.

plurals
  1. POCan't read program output
    primarykey
    data
    text
    <p>So I'm learning C++ today and I've come across a little problem that I can't seem to solve. When I write a program to input information from a user, the program closes right after the user inputs the information and does not display the inputed information. </p> <p>So for example, here's the code: </p> <pre><code>#include &lt;iostream&gt; #include &lt;string&gt; using namespace std; int main() { //Declar vairables char letter = 'A'; int integer = 0; float dec = 0.0f; cout &lt;&lt; "Enter a letter: "; cin &gt;&gt; letter; cout &lt;&lt; "Enter an integer: "; cin &gt;&gt; integer; cout &lt;&lt; "Enter a float number: "; cin &gt;&gt; dec; cout &lt;&lt; endl; //Output what user entered cout &lt;&lt; "letter: " &lt;&lt; letter &lt;&lt; endl; cout &lt;&lt; "integer: " &lt;&lt; integer &lt;&lt; endl; cout &lt;&lt; "float number: " &lt;&lt; dec &lt;&lt; endl; } </code></pre> <p>Now when I run this, the console asks me to: </p> <ol> <li>Input a letter</li> <li>Input an integer</li> <li>Input a float number</li> </ol> <p>After this though, the program instantly closes without displaying the output that this segment of code is supposed to do:</p> <pre><code>//Output what user entered cout &lt;&lt; "letter: " &lt;&lt; letter &lt;&lt; endl; cout &lt;&lt; "integer: " &lt;&lt; integer &lt;&lt; endl; cout &lt;&lt; "float number: " &lt;&lt; dec &lt;&lt; endl; } </code></pre> <p>This has me scratching my head as there are no compiling errors, and the code is ripped straight out of <em>C++ Programming for Games</em> by eInstitute Publishing. </p>
    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.
 

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