Note that there are some explanatory texts on larger screens.

plurals
  1. POWhat is the correct way to write this program?
    text
    copied!<p>My problem is to modify a given program that prints a pyramid of stars such that it prints that same pyramid of stars upside-down.</p> <p>I gave this program much thought and even had a previous question posted about this same program. Since that post I been trying to produce the desired output and I DID! But I feel like I cheated because it most likely is not the way it is intended to be solved. Please show me the correct way write this program. I want my code to be professional/proper.</p> <p>The Given Code:</p> <pre><code>#include &lt;iostream&gt; using namespace std; int main() { int empty = 10; // stars intial value int light = 0; // space inital value int lines; // number of lines on screen int stars; // number of stars each iteration int spaces; // number of spaces each iteration for(lines = 0; lines &lt;= 10; lines++) // number of lines { for(spaces = empty; spaces &gt; 0; spaces--) // number of spaces { cout &lt;&lt; " "; } for(stars = 1; stars &lt; light; stars++) // number of stars { cout &lt;&lt; "*"; } cout &lt;&lt; endl; light += 2; empty--; } int pause; cin &gt;&gt; pause; return 0; } </code></pre> <p>My Modified Code:</p> <pre><code>#include &lt;iostream&gt; using namespace std; int main() { int empty = 10; // stars intial value int light = 0; // space inital value int lines; // number of lines on screen int stars; // number of stars each iteration int spaces; // number of spaces each iteration for(lines = 0; lines &lt;= 10; lines++) // number of lines { for(spaces = empty; spaces &gt; 0; spaces--) // number of spaces { cout &lt;&lt; " "; } for(stars = 1; stars &lt; light; stars++) // number of stars { cout &lt;&lt; "*"; } cout &lt;&lt; endl; light += 2; empty--; } ////////////////////////////////////////////////////////////////// cout &lt;&lt; endl; int nEmpty = 10; // stars intial value int nLight = 0; // space inital value int nLines; // number of lines on screen int nStars; // number of stars each iteration int nSpaces; for(nLines = 0; nLines &lt;= 10; nLines++) // number of lines { for(nSpaces = nEmpty; nSpaces &lt; 0; nSpaces++) // number of spaces { cout &lt;&lt; " "; } for(nStars = 19; nStars &gt; nLight; nStars--) // number of stars { cout &lt;&lt; "*"; } cout &lt;&lt; endl; nLight -= -2; nEmpty++; } int pause; cin &gt;&gt; pause; return 0; } </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