#include<iostream.h>
#include<iomanip.h> //specific header file
const int MAX=2500; // Maximum size
void readData(double data[], int numValues );//input the value to array
double maxDataValues( double data[], int numValues );//find max value
void scaleValues( double data[], int scaledData[], int numValues, double maxValue);
//change data to scale expression
void displayBarGraph(int scaledData[], int numValues, double maxValue);
//out put the bargraph
void main ()
{
int num, sData[MAX];// the number of bar
double Svalue[MAX];//scaled value[]
cout << endl << \"Enter the number of the bar : \";
cin >> num;
//call function(readData, maxDataValues, scaleValues, displayBarGraph)
readData(Svalue, num);
scaleValues(Svalue, sData, num, maxDataValues(Svalue, num) );
displayBarGraph(sData,num, maxDataValues(Svalue, num) );
}
//--------------------------------------------------------------------
void readData (double data[], int numValues )
//input the value of data[j] arrays
{
int h;
cout << \"List of integer values in the range 0 ~ 2500 :(please input data)\";
//input the data
for ( h = 0; h < numValues; h++ )
cin >> data[h];
//data[h]related the line size
}
//---------------------------------------------------------------------
double maxDataValues ( double data[], int numValues )
{
int i;
double maxValue=0;
for( i = 0 ; i < numValues; i++ )
{
if (maxValue < data[i]) // finding max in array[i]s\' value
maxValue= data[i];//change maxValue to largest data[i]
}
return maxValue;//return max Value
}
//------------------------------------------------------------------------------------
void scaleValues ( double data[], int scaledData[], int numValues, double maxValue)
//resize data[]
{
int h;
for(h=0 ; h<numValues ; h++ )
scaledData[h]= (int)(data[h]*50/maxValue);
//expression of scaledData[h]
}
void displayBarGraph (int scaledData[], int numValues, double maxValue)
{
int i,h;
cout<< \"0\" << setw((int) maxValue) << maxValue << endl;
//setw(n) is blank of number
for(i=0; i<=maxValue; i++)//set standard graph.
{
if(( ((int)maxValue)%5)==0)
cout<<\"|\";
else
cout<<\"-\";
}
for(i=0 ; i<numValues ;i++ )//output \'*\'graph about resized
{
for(h=0; h<=scaledData[h] ;h++ )
cout<<\"*\";
cout<<endl;
}
}
에러는 없는게 결과가 쒯다뻑이야 ㅠ0ㅠ
0 100
|-----|-----| .................................. |
|******
|****
뭐 이런식으로 나와야 하는데 ㅠ_ㅠ
배운지 얼마안되서 잘 모르겠어 ㅠ_ㅠ
근데 솔직하게말해라 이거 복사했냐 니가짯냐
니가 짯으면 이거 결과가 이상하게 나온다고 징징될리가없다