Created
October 10, 2012 12:18
-
-
Save juanfal/3865246 to your computer and use it in GitHub Desktop.
simple histogram made with a for loop
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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