Hi,
I am not sure where the memory leak is in this program or why it is crashing. Could you please review the code for me and point out where I am going wrong?
Thanks,
QUESTION
Put together a program that keeps track of monetary contributions to the Society
for the Preservation of Rightful Influence. It should ask the user to enter the number
of contributors and then solicit the user to enter the name and contribution of
each contributor.The information should be stored in a dynamically allocated array
of structures. Each structure should have two members: a character array (or else a
string object) to store the name and a double member to hold the amount of the
contribution.After reading all the data, the program should display the names and
amounts donated for all donors who contributed $10,000 or more.This list should
Programming Exercises 303
be headed by the label Grand Patrons.After that, the program should list the
remaining donors.That list should be headed Patrons. If there are no donors in one
of the categories, the program should print the word “none.”Aside from displaying
two categories, the program need do no sorting.
Code:
#include <iostream>
#include <string>
using namespace std;
struct donors
{
char names[80];
double contribution;
};
int main()
{
int size = 0;
donors *people = new donors[size];
cout << "Enter the amount of contributers" << endl;
cin >> size;
for (int i = 0; i < size; i++)
{
cout << "\nContributer no. " << (i + 1) << endl;
cout << "Enter name:\t";
cin >> people[i].names;
cout << "Enter the amount donated\t";
cin >> people[i].contribution;
}
cout << endl;
for (int j = 0; j < 3; j++)
{
if (people[j].contribution >= 10000)
{
cout << "\nGrand Patrons: " << endl;
cout << people[j].names << " donated "<< people[j].contribution << endl;
}
else if (people[j].contribution < 10000)
{
cout << "\nPatrons: ";
cout << people[j].names << " donated " << people[j].contribution << endl;
}
else if (size = 0)
{
cout << "\nNone" << endl;
}
}
delete[] people;
system("PAUSE");
return 0;
}