I'm trying to write a program that basically inputs info into an array, and then outputs it again in something approaching a table. Like the topic title suggests, it compiles, but doesn't run, instead shutting down with the windows error: x has encountered an error and needs to close.... I have no idea why it's shutting down. Could someone at least point me in the direction of what's going wrong?
I'm using MSVC++ Exp. V. 8.0 to compile it.
Here's the source:
Code:
//EOC Exercise 6.1 - Grading students
#include <iostream>
#include <string>
#include <iomanip>
#include <cctype>
using std::cin;
using std::cout;
using std::endl;
using std::string;
using std::setw;
int main() {
const int max_number_of_students = 100;
char control = 0;
int index = 0;
string students[max_number_of_students] = {0};
int grades[max_number_of_students] = {0};
do {
cout << "Enter the name of the student: ";
cin >> students[index];
cout << "Enter the students grade: ";
cin >> grades[index];
index++;
cout << "Do you need to enter another grade? (y/n)";
cin >> control;
} while((index <= max_number_of_students) | (std::tolower(control)) != 'y');
if(index >= max_number_of_students)
cout << "\nMaximum reached!";
float average = 0;
for(int i_avg = 0; i_avg <= index; i_avg++)
average += static_cast<float>(grades[i_avg]);
cout << endl << "The average grade is: " << (average / static_cast<float>(index)) << " points.";
for(int table_index = 0; table_index <= index; table_index++){
cout << setw(10) << students[table_index] << ": "
<< setw(5) << grades[table_index];
}
return 0;
}
I'm trying to teach myself C++. I've got a book and stuff (Ivor Horton's:Beginning C++, if anyone is concerned), and I think I'm making progress, so excuse me if I sound like an idiot.