Hi there,
I'm trying to learn using stuctures and I've come up with a little thing that combines them with loops and arrays. It might not be a very elegant solution if it did work but instead it lets me enter a few fields and then it flags up a segmentation error.
I know that a segmentation error is something to do with memory being accessed when it shouldn't be or something like so the only thing I can think of is that I might have written past an array but I don't see it.
Many thanks for your insights.
Here is the code:
Code:#include <iostream> #include <string> using namespace std; struct record { string name; int refnumber; float salary; }; int main() { record employees[2]; cout << "\t\t*** RECORD FILES ***/n/n"; for (int i = 0; i < 3; i++) { cout << "\nPlease enter employee's name: "; cin >> employees[i].name; cout << "\nPlease enter 4 digit reference number: "; cin >> employees[i].refnumber; cout << "\nPlease enter salary: "; cin >> employees[i].salary; } cout << "\t\t*** DATA SUMMARY ***\n\n"; for (int i = 0; i < 3; i++) { cout << employees[i].name << " is ref number " << employees[i].refnumber << " on a salary of " << employees[i].salary; } return 0; }