when I run this program in dev C++ I get a windows error screen that pops up but it compiles and runs; However, if I run this in visual C++ 6.0 it runs just fine and is error free? Any suggestions?
FILE INPUT:
76 89 150 135 200 76 12 100 150 28 178 189 167 200 175 150 87 99 129 149 176 200 87 35 157 189
Code:#include <cstdlib> #include <iostream> #include <fstream> #include <string> #include <iomanip> using namespace std; // prototypes void get_student_grade(int range[8], ifstream& infile, int& score); void fill_array_boundaries(string boundaries[8]); void print_results(string boundaries[8], int range[8]); //////////////////////////////////////////////////////////////////////////// int main(int argc, char *argv[]) { int range[8]; string boundaries[8]; int score; ifstream infile; infile.open("C:\\scoresin.txt"); get_student_grade(range, infile, score); fill_array_boundaries(boundaries); print_results(boundaries, range); infile.close(); system("PAUSE"); return EXIT_SUCCESS; } ////////////////////////// Function definitions ////////////////////////// // get student grades and find the frequency for each range. void get_student_grade(int range[8], ifstream& infile, int& score) { // initialize array range. int i; for(i =0; i<=8; i++) range[i] = 0; //--------------------// do{ infile >> score; // input score from file. if(score >= 0 && score <= 24) range[0] = range[0] + 1; if(score >= 25 && score <= 49) range[1] = range[1] + 1; if(score >= 50 && score <= 74) range[2] = range[2] + 1; if(score >= 75 && score <= 99) range[3] = range[3] + 1; if(score >= 100 && score <= 124) range[4] = range[4] + 1; if(score >= 125 && score <= 149) range[5] = range[5] + 1; if(score >= 150 && score <= 174) range[6] = range[6] + 1; if(score >= 175 && score <= 200) range[7] = range[7] + 1; }while(!infile.eof()); } // initialize array with score boundaries void fill_array_boundaries(string boundaries[8]) { boundaries[0]= " 0 - 24"; boundaries[1] = " 25 - 49"; boundaries[2] = " 50 - 74"; boundaries[3] = " 75 - 99"; boundaries[4] = "100 - 124"; boundaries[5] = "125 - 149"; boundaries[6] = "150 - 174"; boundaries[7] = "175 - 200"; } void print_results(string boundaries[8], int range[8]) { int i; cout << "Score Boundaries" << setw(35) << "Number of Students" << endl; for(i = 0; i <= 8; i++) cout << boundaries[i] << " " << setw(30) << right << range[i] << endl; }



LinkBack URL
About LinkBacks


