I am a novice @ coding right now, and am getting it by trial and error, when i run this program after the 2nd round of input it skips some of the steps and then crashes. I threw the if (i > 0) to help bypass it on the first pass. Something must just be plain wrong. Can someone shed some light?
//Exc_6.cpp - Patrons and donations
#include <iostream>
#include <string>
using namespace std;
struct contributors
{
string name;
double donation;
};
int main()
{
int numberOfContributors;
cout << "Please input the number of contributors: ";
cin >> numberOfContributors;
cin.ignore( numeric_limits <streamsize> ::max(), '\n' );
contributors * thePatrons = new contributors [];
for (int i = 0; i < numberOfContributors; i++)
{
cout << "Please input the name: ";
if (i > 0)
cin.ignore( numeric_limits <streamsize> ::max(), '\n' );
getline(cin, thePatrons[i].name);
cout << "Please input the donation ammount: ";
cin >> thePatrons[i].donation;
cin.ignore( numeric_limits <streamsize> ::max(), '\n' );
}
contributors * grandPatrons = new contributors [];
contributors * regularPatrons = new contributors [];
int j = 0, k = 0;
for (int i = 0; i < numberOfContributors; i++)
{
if (thePatrons[i].donation > 10000)
{
grandPatrons[j].name = thePatrons[i].name;
grandPatrons[j].donation = thePatrons[i].donation;
j++;
}
else
{
regularPatrons[k].name = thePatrons[i].name;
regularPatrons[k].donation = thePatrons[i].donation;
k++;
}
}
cout << "The grand patrons are as follow: " << endl;
for (int i = 0; i < j; i++)
{
cout << grandPatrons[i].name << "\t\t" << grandPatrons[i].donation << endl;
}
cout << "The regular patrons are as follow: " << endl;
for (int i = 0; i < k; i++)
{
cout << regularPatrons[i].name << "\t\t" << regularPatrons[i].donation << endl;
}
delete [] regularPatrons;
delete [] grandPatrons;
delete [] thePatrons;
system("PAUSE");
}