I need this to make a histogram of the users...i am not sure how to do it

I am new at c++ and this program is supposed to look at whether the customer is amazed, pleased, ect. but i can't figure it out....i need help asap...this is my code put there are alot of errors...

#include <iostream>
#include <cstdlib>
#include <ctime>
#include <cmath>
#include <iomanip>
#include <fstream>
#include <string>
using namespace std;

const int ARRAY_SIZE = 5;

void compute_wait_time(int arrival[], int service[], int wait[], int );
int FindMin(int arr[]);
int FindMax(int arr[]);
int RangeWait(int max, int min);
double Mean(int wait[]);
double STD(const int wait[], double mean);
void computeFrus(double mean, double std, int wait[], int amazed=0, int pleased=0, int calm=0,
int irritated=0, int berserk=0);
void computeHisto (int amazed, int pleased, int calm, int irritated, int berserk, int i=0);

int main()
{
int arrival[ARRAY_SIZE],
service[ARRAY_SIZE],
wait[ARRAY_SIZE],
teller[ARRAY_SIZE],
max, min, range, sum;
double mean;

ifstream infile;
infile.open("bankSMALL.txt");

if(infile)
{
cout<< "File is Opened" << endl;
cout<< "ID Arrival Service Wait"<<endl;
}

else
{
cout<< "File Not Found"<< endl;
}

// read data
for (int i=0;i<ARRAY_SIZE;i++) {
infile >> teller[i];
infile >> arrival[i];
infile >> service[i];
}

compute_wait_time(arrival,service,wait, ARRAY_SIZE);

//echoprint data
for (int i=0;i<ARRAY_SIZE;i++)
{
cout << teller[i] <<" ";

if (arrival[i] < 100000)
{
cout<< "0";
cout<< arrival[i]<< " " ;
}
else
{
cout<< arrival[i]<< " " ;
}

if (service[i] < 100000)
{
cout<< "0";
cout<< service[i]<< " " ;
}
else
{
cout<< service[i]<< " " ;
}

cout << wait[i] << endl;
}

max = FindMax(wait);
min = FindMin(wait);
range = RangeWait(max,min);

cout<< endl;
cout<< "The Range is : " << range << endl;


mean = Mean(wait);
cout<< "mean is " << mean << endl;

double std = STD(wait, mean);
cout << "std is " << std << endl;


void computeFrus(double mean, double std, int wait[], int amazed=0, int pleased=0, int calm=0,
int irritated=0, int berserk=0);
void computeHisto (int amazed, int pleased, int calm, int irritated, int berserk, int i=0);



return(0);
}



void compute_wait_time(int arrival[], int service[], int wait[], int ARRAY_SIZE)
{
int hours_arr, mins_arr, sec_arr, arrival_sec;
int hours_ser, mins_ser,sec_ser,service_sec;

for(int i=0; i<ARRAY_SIZE; i++)
{

// calculate arrival in seconds
hours_arr = arrival[i] / 10000 ;
mins_arr = (arrival[i] - (hours_arr * 10000))/100 ;
sec_arr = arrival[i] - ((hours_arr * 10000) + (mins_arr * 100)) ;
arrival_sec = ((hours_arr * 3600) + (mins_arr * 60) + sec_arr);

// calculate service in seconds
hours_ser = service[i] / 10000 ;
mins_ser = (service[i] - (hours_ser * 10000))/100 ;
sec_ser = service[i] - ((hours_ser * 10000) + (mins_ser * 100)) ;
service_sec = ((hours_ser * 3600) + (mins_ser * 60) + sec_ser);

wait[i] = service_sec - arrival_sec;

}

}


int FindMin(int arr[])
{
int current, min;

min = arr[0];
for(int i=1; i<ARRAY_SIZE; i++)
{
current = arr[i];
if(current < min)
{
min = current;
}
}
return(min);
}

int FindMax(int arr[])
{
int current, max;
max = arr[0];
for (int i=1; i<ARRAY_SIZE; i++)
{
current = arr[i];
if(current > max)
{
max = current ;
}
}
return(max);
}


int RangeWait(int max, int min)
{
return (max - min);
}

double Mean(int wait[])
{
double mean;
int sum = 0;
for (int i=0; i<ARRAY_SIZE; i++)
{
sum = sum + wait[i];
}
mean = sum*1.0/ARRAY_SIZE;
//cout<< sum;
return(mean);
}


void computeFrus(double mean, double std, int wait[], int amazed=0, int pleased=0, int calm=0,
int irritated=0, int berserk=0)
{
for(int i=0; i<ARRAY_SIZE; i++)
{
if(wait[i] <= (mean - std))
{
amazed++;
}

else if( (mean - std) < wait[i] || (mean - std)< mean)
{
pleased++;
}

else if( mean <= wait[i] || mean < (mean = std))
{
calm++;
}

else if((mean + std) <= wait[i] || (mean = std) < (mean = (2* std)))
{
irritated++;
}

else if((mean = (2 * std)) <= wait[i])
{
berserk++;
}
}
}

void computeHisto (int amazed, int pleased, int calm, int irritated, int berserk, int i=0)
{
if(int i=0; i<amazed ; i++)
{
cout<<"*";
}

else if (int i=0; i < pleased; i++)
{
cout<<"*";
}

else if (int i=0; i < calm; i++)
{
cout<< "*";
}

else if (int i=0; i < irritated; i++)
{
cout<< "*";
}

else if (int i =0; i < berserk; i++)
{
cout<< "*";
}
}

double STD(const int wait[], double mean)
{
double std;
double sum=0;
double waitmean;

for (int i=0; i<ARRAY_SIZE; i++)
{
waitmean = wait[i]-mean;
waitmean = waitmean * waitmean;
sum = sum + waitmean;
}

std = sqrt (sum / (ARRAY_SIZE - 1));


return std;
}
Last edited on
Make the player variable into a 2 element array and swap between 0 and 1 for player 1 and 2.
Topic archived. No new replies allowed.