You are using a version without Ads of this website. Please, consider donating:

### Output is nt showing even though the file is open

#include <iostream>
#include <iomanip>
#include <fstream>
#include <string>
#include <math.h>
using namespace std;

//Mean calculation

double avg (double x) {
double count=0,avg,i,stud[20],sum=0;
string inname="input.txt";
ifstream infile (inname);
ofstream outfile ("output.txt");
for (int k=0;k<20;k++) {
while (infile>>i) {
count++;
stud[k]=i;
sum=sum+stud[k];
}
}
x=sum/count;
return x;
}

//Std.Deviation Calculation

double stdviation (double x) {
double dviation,power;
string inname="input.txt";
ifstream infile (inname);
ofstream outfile ("output.txt");
for (int k=0;k<20;k++) {
while (infile>>i) {
count++;
stud[k]=i;
stud[k]=pow(stud[k],2);
sum=sum+stud[k];
}
}
power=pow(avg(x),2);
var=sum/count;
var=var-power; // This will be the variance
dviation=sqrt(var);
return dviation;
}

//Barchart Drawing

void barchart () {
string inname="input.txt";
ifstream infile (inname);
ofstream outfile ("output.txt");
double stud[20],countA=0,countB=0,countC=0,countD=0;
double countF=0,i;
if (outfile.is_open()) {
for (int x=0;x<30;x++) {
while (infile>>i) {
stud[x]=i;
if(stud[x]<40){
countA++;
}else if(stud[x]<50){
countB++;
}else if(stud[x]<70){
countC++;
}else if(stud[x]<80){
countD++;
}else if(stud[x]<=100){
countF++;
}
outfile.close();
}
}

}
cout<<endl;
cout<<"A"<<setw(15);;
outfile<<"A"<<setw(15);
for(int numA=0;numA < countA;numA++){
outfile<<"*";
cout<<"*";
}
cout<<endl;
outfile<<endl;
cout<<"B"<<setw(15);
outfile<<"B"<<setw(15);
for(int numB=0;numB < countB;numB++){
outfile<<"*";
cout<<"*";
}
cout<<endl;
outfile<<endl;
cout<<"C"<<setw(15);
outfile<<"C"<<setw(15);
for(int numC=0;numC < countC;numC++){
outfile<<"*";
cout<<"*";
}
cout<<endl;
outfile<<endl;
cout<<"D"<<setw(15);
outfile<<"D"<<setw(15);
for(int numD=0;numD < countD;numD++){
outfile<<"*";
cout<<"*";
}
outfile<<endl;
cout<<endl;
outfile<<"F"<<setw(15);
cout<<"F"<<setw(15);
for(int numF=0;numF < countF;numF++){
outfile<<"*";
cout<<"*";
}
cout<<endl;
cout<<endl;
cout<<endl;
}

//Main function
void main () {
double count=0,i,stud[20],sum=0,x=0;
string inname="input.txt";
ifstream infile (inname);
ofstream outfile ("output.txt");
if (!infile && outfile) {
}
for (int k=0;k<20;k++) {
while (infile>>i) {
count++;
stud[k]=i;
cout<<"Mark of student "<<count<<" : "
<<stud[k]<<endl;
}
}
cout<<endl;
barchart ();
cout<<endl;
system ("pause");
}

Above is my program where i need to read a sequence of marks from txt.file and calculate its mean and std deviation and then write on another txt file. I'm having problem in writing the data onto txt.files now. It's showing blank page. Can anyone tell me what gone wrong in the code above ??