PDA

View Full Version : shorting numbers


truviet911
10-22-2009, 06:02 AM
i need some help with how to short numbers in to range. examples

00-09: *
10-19: **
20-29: ***
30-39: ****
40-49: *****
50-59: ****
60-69: ***
70-79: **
80-89: *
90-99: *

ex: range 10-19 it has number 15, 17 in it therefore it has 2 asterisks. here is my random number code:


#include <cstdlib>
#include <ctime>
#include <iostream>

using namespace std;

int main()
{
srand((unsigned)time(0));
int random_integer;
for(int index=0; index<50; index++){
random_integer = (rand()%50)+10;
cout << random_integer << endl;
}
system("pause");
}

Trinithis
10-22-2009, 10:28 AM
If you mean sorting:
http://www.cplusplus.com/reference/clibrary/cstdlib/qsort/

oracleguy
10-22-2009, 05:21 PM
Create a one dimensional integer array with 10 elements. Then when you take a number in, divide it by 10 and then round it down. You can use that as the index into the array and increment the count in the array by 1.

Then when you are done, to display your histogram, you'd just loop through the array and print out as many stars as stored in the integer at that index.