Note that there are some explanatory texts on larger screens.

plurals
  1. POC++ Whats wrong with my logic?
    primarykey
    data
    text
    <p>I'm just learning C++ and I need this program to work for class. Logically it works. I'm using bloodshed.net's IDE... and it seems to just ignore the <code>cin &gt;&gt; kwh;</code>. I think its bloodsheds fault, not mine, but I could be mistake.</p> <p>Here the code:</p> <pre><code>#include &lt;iostream&gt; #include &lt;iomanip&gt; using namespace std; int main() { double kwh = -1, monthCost = 0, totalCost = 0; int monthCount = 0; bool nextMonth = 0; do { kwh = -1; cout &lt;&lt; "How many KWH did you use month " &lt;&lt; ++monthCount &lt;&lt; "?\n"; cin &gt;&gt; kwh; if (kwh &lt;= 1000 &amp;&amp; kwh &gt;= 0) { monthCost = kwh * 0.6; } else if (kwh &lt; 0) { cout &lt;&lt; "\nInvalid number of KWH."; while (kwh &lt; 0) { cout &lt;&lt; "How many KWH did you use month " &lt;&lt; monthCount &lt;&lt; "?\n"; // Could you tell me what I'm doing wrong? I honestly think its // the programs fault, not mine. Driectly below this comment // I'm asking the user for the KWH and it just ignores it // when I compile and run. WHY?!? cin &gt;&gt; kwh; } } else if (kwh &gt; 1000) { monthCost = ((kwh - 1000) * 0.45) + 600; } totalCost += monthCost; cout &lt;&lt; "\nYour electric bill for this month " &lt;&lt; monthCount &lt;&lt; " is $" &lt;&lt; monthCost &lt;&lt; ".\n"; cout &lt;&lt; "Would you like to enter another month? (1/0)\n"; cin &gt;&gt; nextMonth; cout &lt;&lt; "\n"; } while (nextMonth == 1); cout &lt;&lt; "\n\nYour total for all " &lt;&lt; nextMonth &lt;&lt; " month(s) is %" &lt;&lt; totalCost &lt;&lt; ".\n"; system("pause"); } </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.
 

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