Doing barchart input from file got problem

This my code i am doing a bar chart that input from file but it can't works.
can anyone of you help me??

#include <iostream>
#include <cmath>
#include <iomanip>
#include <fstream>
using namespace std;
int main ()
{
int psi[7];
int psiall=0;
int counter=0;
long double sum=0;
long double average,sd;
long double variance=0;
long double sumsqr=0;
double value;
ifstream mypsi("allpsi.txt");
ifstream psi1("allpsi.txt");
cout <<"Hi,User!\n";
cout <<"So, we will help you to calculate your Total of PSI, mean and standard deviation.\n";

for (int day = 1; day <= 7; day++)
{


mypsi>>psiall;
cout << "The day " << day << " psi is: "<<psiall<<"\n";
sum+=psiall;
sumsqr+=pow(psiall,2);


}
cout << "The total PSI : " <<sum<<"\n";
average=sum/7;
cout << "The mean : " <<average<<"\n";
variance = (sumsqr/7) - pow(average,2);
sd=sqrt(variance);



cout << "The standard deviation : "<<sd<<"\n";



cout<<"Bar Chart\n";
cout<<"==================================================\n";
cout<<"Good\t";
for(int i=1;i<7;i++){
psi1>>psi;
psi[i]=psi/50;
}
for(int c=0;c<psi[c] ;c++){
cout<<"*";

}





return 0;

}
You can't read from a stream into an array. You need to specify an array index.
1
2
3
4
5
for (int i = 1; i<7; i++)
  {
    psi1 >> psi; // maybe you meant psi[i] ?????
    psi[i] = psi / 50;
  }
now i change already

#include <iostream>
#include <cmath>
#include <iomanip>
#include <fstream>
using namespace std;
int main ()
{
int psi=0;
int psiall=0;
int generate[4];
long double sum=0;
long double average,sd;
long double variance=0;
long double sumsqr=0;
int c1=0;
double value;
ifstream mypsi("allpsi.txt");
ifstream psi1("allpsi.txt");
cout <<"Hi,User!\n";
cout <<"So, we will help you to calculate your Total of PSI, mean and standard deviation.\n";

for (int day = 1; day <= 7; day++)
{
mypsi>>psiall;
cout << "The day " << day << " psi is: "<<psiall<<"\n";
sum+=psiall;
sumsqr+=pow(psiall,2);
}

cout << "The total PSI : " <<sum<<"\n";
average=sum/7;
cout << "The mean : " <<average<<"\n";
variance = (sumsqr/7) - pow(average,2);
sd=sqrt(variance);



cout << "The standard deviation : "<<sd<<"\n";


cout<<"\n";
cout<<"Bar Chart\n";
cout<<"==================================================\n";
cout<<"Air Quality\t\t\t"<<"PSI\n";
cout<<"--------------------------------------------------\n";


while(mypsi>>psi){

for (int bar=0; bar<=generate[0] ; bar++ ){


if(psi>=0 && psi<=50){
generate[0] +=1;
}

else if (psi>=51 && psi<=100){
generate[1] +=1;
}

else if (psi>=101 && psi<=200){
generate[2] +=1;
}

else if (psi>=201 && psi<=300){
generate[3] +=1;
}

else if (psi>=300){
generate[4] +=1;
}
cout<<"*";

}



}
return 0;

}
but still cannot work
What does not work?

What results do you expect and what do you get ?
Topic archived. No new replies allowed.