Duke523
04-11-2004, 11:52 PM
I have a C++ program assignment and when I run my program it gives me a core dump. I need some help big time especially since it is due monday. :(
Here is a copy of my program and its input file
//**********This is the comments section********************************
// Author: Chris Duke
// Email: cduke@butler.edu
// Date due: April 7th, 2004
// Program 5: This program will take an input file
// calculate the average of grades and store output
// in a output file.
//**********My comments end here****************************************
#include<iostream>
#include<fstream>
#include<cstdlib>
using namespace std;
int main()
{
char cont = 'y', name;
while(cont == 'y')
{
char input_file[15];
ifstream in_s;
cout<< "Please input the input file name \n";
cin>> input_file;
in_s.open(input_file);
if(in_s.fail())
{
cout<<"Input file opening failed. \n";
exit(1);
}
char output_file[15];
ofstream out_s;
cout<< "Please input the output file name \n";
cin>> output_file;
out_s.open(output_file);
if(out_s.fail())
{
cout<<"Output file opening failed. \n";
exit(1);
}
do
{
int sum=0,aver=0,grade=0;
char lastname[25], firstname[25];
in_s>>lastname>>firstname;
out_s<<lastname<<" "<<firstname<<" ";
for(int count=0; count<= 9; count++)
{
in_s>>grade;
sum = sum + grade;
out_s<<grade<<" ";
}
aver = sum / 10;
out_s<<aver<<endl;
}while(!in_s.eof());
in_s.close();
out_s.close();
cout<< "Would you like to compute another set of grades? <y/n>" <<endl;
if(cont == 'y'||'n')
{
cin>> cont;
}
else
{
cout<< "You have entered an invalid choice." <<endl;
cout<< "Would you like to compute another set of grades? <y/n>" <<endl;
cin>> cont;
}
}
cout<< "Thanks for using"<<endl<<"*^*THE GRADE COMPUTEING PROGRAM*^*" <<endl;
return 0;
}
And input file reads:
Smith John 75 86 72 90 66 82 95 57 88 80
Peterson Mary 65 80 78 91 76 72 90 50 87 85
Dalton Nick 55 46 79 98 68 82 99 87 58 100
Robinson Carla 83 76 32 80 96 62 95 77 98 81
Hamilton Petter 45 76 71 90 61 89 94 58 68 89
Gilbert Jeffrey 72 83 74 95 67 86 98 59 80 77
Bush John 95 96 82 69 76 82 95 97 98 90
Here is a copy of my program and its input file
//**********This is the comments section********************************
// Author: Chris Duke
// Email: cduke@butler.edu
// Date due: April 7th, 2004
// Program 5: This program will take an input file
// calculate the average of grades and store output
// in a output file.
//**********My comments end here****************************************
#include<iostream>
#include<fstream>
#include<cstdlib>
using namespace std;
int main()
{
char cont = 'y', name;
while(cont == 'y')
{
char input_file[15];
ifstream in_s;
cout<< "Please input the input file name \n";
cin>> input_file;
in_s.open(input_file);
if(in_s.fail())
{
cout<<"Input file opening failed. \n";
exit(1);
}
char output_file[15];
ofstream out_s;
cout<< "Please input the output file name \n";
cin>> output_file;
out_s.open(output_file);
if(out_s.fail())
{
cout<<"Output file opening failed. \n";
exit(1);
}
do
{
int sum=0,aver=0,grade=0;
char lastname[25], firstname[25];
in_s>>lastname>>firstname;
out_s<<lastname<<" "<<firstname<<" ";
for(int count=0; count<= 9; count++)
{
in_s>>grade;
sum = sum + grade;
out_s<<grade<<" ";
}
aver = sum / 10;
out_s<<aver<<endl;
}while(!in_s.eof());
in_s.close();
out_s.close();
cout<< "Would you like to compute another set of grades? <y/n>" <<endl;
if(cont == 'y'||'n')
{
cin>> cont;
}
else
{
cout<< "You have entered an invalid choice." <<endl;
cout<< "Would you like to compute another set of grades? <y/n>" <<endl;
cin>> cont;
}
}
cout<< "Thanks for using"<<endl<<"*^*THE GRADE COMPUTEING PROGRAM*^*" <<endl;
return 0;
}
And input file reads:
Smith John 75 86 72 90 66 82 95 57 88 80
Peterson Mary 65 80 78 91 76 72 90 50 87 85
Dalton Nick 55 46 79 98 68 82 99 87 58 100
Robinson Carla 83 76 32 80 96 62 95 77 98 81
Hamilton Petter 45 76 71 90 61 89 94 58 68 89
Gilbert Jeffrey 72 83 74 95 67 86 98 59 80 77
Bush John 95 96 82 69 76 82 95 97 98 90