Skip to content

Instantly share code, notes, and snippets.

@juanfal
Created October 10, 2012 12:18
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save juanfal/3865246 to your computer and use it in GitHub Desktop.
Save juanfal/3865246 to your computer and use it in GitHub Desktop.
simple histogram made with a for loop
// 15.histogram.cpp
// juanfc 2009-10-30
// ask for numbers until 0, making a simple histogram with them
// It looks better if you enter all the numbers in a row. Ex:
// 1 2 4 5 6 4 3 2 7 8 9 10 0
#include <iostream>
using namespace std;
int main()
{
float x;
do {
cin >> x;
if (x == 0) break;
// x + 0.5 to round it up
for ( int i = 1; i <= x + 0.5; ++i ) {
cout << "*";
}
cout << endl;
} while ( true );
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment