Note that there are some explanatory texts on larger screens.

plurals
  1. POMy values keep adding up, instead of resetting in my loop statement
    text
    copied!<p>I'm not sure whether one of my formulas are wrong, I placed something in the wrong area, or I'm missing something completely. But when I run the prog. It would add up the prices of meals from a previous table of customers, instead of resetting for each new table. Any help?</p> <pre><code>int main () { //These are the variables used for the formulas and inputs. int people, counter; float price, subtotal, tip, tax, total; cout&lt;&lt;"How many people are at the table?" &lt;&lt;endl; cin&gt;&gt;people; //Use a while statement to start a loop while (people!=0) { //Use a for statement inside the while to make a nested loop. It will ask the price of each meal. for(counter=1; counter&lt;=people; counter++) { cout&lt;&lt;"How much is the meal?: " &lt;&lt;endl; cin&gt;&gt;price; subtotal+=price; tax=subtotal*.06; if (people&lt;5) { tip=subtotal*.18; } else tip=subtotal*.20; total=tax+subtotal+tip; } //This is the final output for the program. Which will be the bill. cout&lt;&lt;setprecision(2) &lt;&lt;fixed; cout&lt;&lt;left; cout&lt;&lt;setw(20)&lt;&lt;"Subtotal: " &lt;&lt;"$" &lt;&lt;subtotal &lt;&lt;endl; cout&lt;&lt;setw(20)&lt;&lt;"Sales Tax: " &lt;&lt;"$" &lt;&lt;tax &lt;&lt;endl; cout&lt;&lt;setw(20)&lt;&lt;"Tip: " &lt;&lt;"$" &lt;&lt;tip &lt;&lt;endl; cout&lt;&lt;setw(20)&lt;&lt;"Total: " &lt;&lt;"$" &lt;&lt;total &lt;&lt;endl; cout&lt;&lt;" " &lt;&lt;endl; cout&lt;&lt;setw(20)&lt;&lt;"How many people are at the table?" &lt;&lt;endl; cin&gt;&gt;people; } </code></pre>
 

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