This is another question from 'Jumping into C++' by Alex Allain. Specifically, part of a practice problem 7 from the end of Chapter 5.
It reads "The program should then show the results of the poll—try making a
bar graph that shows the results properly scaled to fit on your screen no matter how many results were entered."
I didn't want to inconvenience anybody with a long wall of text so I'm omitting the part of the program that introduces the poll question and tallies the votes for each answer option. That part is working fine.
Here is my attempt at graph making :
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25
|
for ( int sum1g = sum1; sum1g > 0; sum1g-- ) /* uses value stored in sum1 after while loop is terminated to initialize a new variable sum1g.
Essentially recounts the votes for option 1 and displays a * for each vote */
{
cout << "*\n";
}
cout << '\n';
cout << "B\n";
for ( int sum2g = sum2; sum2g > 0; sum2g-- )
{
cout << "*\n";
}
cout << '\n';
cout << "P\n";
for ( int sum3g = sum3; sum3g > 0; sum3g-- )
{
cout << "*\n";
}
cout << '\n';
cout << "C\n";
|
This gives me something sorta kinda resembling what I want.. a vertical column of asterisks denoting the number of votes for each option. However, they're just stacked one after another and for a true 'bar graph' I need them to be side by side.
^ How the output looks now
*
*
* *
* * *
* * *
B P C
|
^ How I'd like it to be
I have a sneaking suspicion nested loops might be the answer.. but I'm not totally sure. I've tried nesting the three for loops I showed above but that just made a big mess x)
Once the graph displays properly, I'm also not sure how to ensure a graph scales to fit the screen no matter how many asterisks (votes) are tallied.
I apologize if anything about my post is confusing.. just tried to keep the length down (and still failed). I can of course post the entire program code if need be. Thanks so much for any help you might be able to provide!