Advice on Histogram
Hi There
I would like some advice on my code to produce histogram for marks...Just looking for guidance if I am on the right track...
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 26 27 28 29 30 31 32 33
|
#include <iostream.h>
#include <iomanip.h>
#include <cmath.h>
int main()
{
for (i=0; i<10;i++)
{
if ((data[j] >= 10*i) && (data[j] < 10*i+9)) {bin[i]++; }//increment data selection
}
cout << "00-09: ";
cout << "10-19: ";
cout << "20-29: ";
cout << "30-39: ";
cout << "40-49: ";
cout << "50-59: ";
cout << "60-69: ";
cout << "70-79: ";
cout << "80-89: ";
cout << "90-99: ";
cout << ":100 ";
for (i=0;i<bin[j];i++) {cout << "*"; }//for eachg selection data count with *
cout << endl;
}
cin>>hold;
return (0);
}
|
Many Thanks
I would say ... no.
You are using old-style headers. Do this instead:
1 2 3 4
|
#include <iostream>
#include <iomanip>
#include <cmath>
using namespace std;
|
You have many undeclared variables. At least make the thing able to compile!
You seem to want a horizontal graph, in which case you will need your cout<<"00-09: ", etc, inside the second loop.
Topic archived. No new replies allowed.