Note that there are some explanatory texts on larger screens.

plurals
  1. POVertical Bar Graphs in C++
    primarykey
    data
    text
    <p>Ok, I'm trying to make a vertical bar graph from the values in a file. The code below works, to a point that is, and prints horizontally, but one asterisk per line, meaning there are spaces (obviously). Not looking for a spoonfed answer, just a push in the right direction.</p> <pre><code>using namespace std; int main() { int counter; cout&lt;&lt;"Please enter a number"&lt;&lt; "\n"; counter=0; char *fname = "C:/Users/Jordan Moffat/Desktop/coursework/problem2.txt"; int x; ifstream infile(fname); while (infile &gt;&gt; x) { if (x==0 &amp;&amp; x&lt;=10){ cout&lt;&lt;"*"&lt;&lt;"\t"&lt;&lt;"\t"&lt;&lt;"\t"&lt;&lt;"\t"&lt;&lt;"\t"&lt;&lt;"\t"&lt;&lt;"\t"&lt;&lt;"\t"&lt;&lt;"\t"&lt;&lt;"\n"; } else if (x&gt;=10 &amp;&amp; x&lt;=20){ cout&lt;&lt;"\t"&lt;&lt;"*"&lt;&lt;"\t"&lt;&lt;"\t"&lt;&lt;"\t"&lt;&lt;"\t"&lt;&lt;"\t"&lt;&lt;"\t"&lt;&lt;"\t"&lt;&lt;"\t"&lt;&lt;"\n"; } else if (x&gt;=20 &amp;&amp; x&lt;=30){ cout&lt;&lt;"\t"&lt;&lt;"\t"&lt;&lt;"*"&lt;&lt;"\t"&lt;&lt;"\t"&lt;&lt;"\t"&lt;&lt;"\t"&lt;&lt;"\t"&lt;&lt;"\t"&lt;&lt;"\t"&lt;&lt;"\n"; } else if (x&gt;=30 &amp;&amp; x&lt;=40){ cout&lt;&lt;"\t"&lt;&lt;"\t"&lt;&lt;"\t"&lt;&lt;"*"&lt;&lt;"\t"&lt;&lt;"\t"&lt;&lt;"\t"&lt;&lt;"\t"&lt;&lt;"\t"&lt;&lt;"\t"&lt;&lt;"\n"; } else if (x&gt;= 40 &amp;&amp; x&lt;=50){ cout&lt;&lt;"\t"&lt;&lt;"\t"&lt;&lt;"\t"&lt;&lt;"\t"&lt;&lt;"*"&lt;&lt;"\t"&lt;&lt;"\t"&lt;&lt;"\t"&lt;&lt;"\t"&lt;&lt;"\t"&lt;&lt;"\n"; } else if (x&gt;=50 &amp;&amp; x&lt;=60){ cout&lt;&lt;"\t"&lt;&lt;"\t"&lt;&lt;"\t"&lt;&lt;"\t"&lt;&lt;"\t"&lt;&lt;"*"&lt;&lt;"\t"&lt;&lt;"\t"&lt;&lt;"\t"&lt;&lt;"\t"&lt;&lt;"\n"; } else if (x&gt;=60 &amp;&amp; x&lt;=70){ cout&lt;&lt;"\t"&lt;&lt;"\t"&lt;&lt;"\t"&lt;&lt;"\t"&lt;&lt;"\t"&lt;&lt;"\t"&lt;&lt;"*"&lt;&lt;"\t"&lt;&lt;"\t"&lt;&lt;"\t"&lt;&lt;"\n"; } else if (x&gt;=70 &amp;&amp; x&lt;=80){ cout&lt;&lt;"\t"&lt;&lt;"\t"&lt;&lt;"\t"&lt;&lt;"\t"&lt;&lt;"\t"&lt;&lt;"\t"&lt;&lt;"\t"&lt;&lt;"*"&lt;&lt;"\t"&lt;&lt;"\t"&lt;&lt;"\n"; } else if (x&gt;=80 &amp;&amp; x&lt;=90){ cout&lt;&lt;"*"&lt;&lt;"\t"&lt;&lt;"\t"&lt;&lt;"\t"&lt;&lt;"\t"&lt;&lt;"\t"&lt;&lt;"\t"&lt;&lt;"\t"&lt;&lt;"*"&lt;&lt;"\t"&lt;&lt;"\n"; } else if (x&gt;=90 &amp;&amp; x&lt;=100){ cout&lt;&lt;"\t"&lt;&lt;"\t"&lt;&lt;"\t"&lt;&lt;"\t"&lt;&lt;"\t"&lt;&lt;"\t"&lt;&lt;"\t"&lt;&lt;"\t"&lt;&lt;"\t"&lt;&lt;"*"&lt;&lt;"\n"; } } cout&lt;&lt;"====================================================================================="&lt;&lt; "\n"; cout&lt;&lt;"0-9"&lt;&lt;"10-19"&lt;&lt;"20-29"&lt;&lt;"30-39"&lt;&lt;"40-49"&lt;&lt;"50-59"&lt;&lt;"60-69"&lt;&lt;"70-79"&lt;&lt;"80-89"&lt;&lt;"90-100"&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.
    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