online compiler and debugger for c/c++

code. compile. run. debug. share.
Source Code   
Language
// This program will determine a household HHincome // Ziyaaein, Lauren // Section 20810 // In class assignment #11 #include<iostream> #include<fstream> #include<string> #include<iomanip> using namespace std; struct HouseHold { string Initials; int Fam; double HHincome; } Family[100]; void getData(int &Size) { ifstream dataIn; dataIn.open("data.txt"); //open file int f = 0; while(!dataIn.eof()) { dataIn >> Family[f].Initials; dataIn >> Family[f].HHincome; dataIn >> Family[f].Fam; f++; } Size = f; dataIn.close(); } void printOutput(int Size) { cout << left << setw(15) << "Family ID " << setw(10) << "Income " << setw(10) << "Number of people " << endl; for(int f= 0; f< Size; f++) { cout << setw(15) << Family[f].Initials << setw(10) << Family[f].HHincome << setw(10) << Family[f].Fam << endl; } } double AvgIncome(int Size) { double Sum = 0; for(int f= 0; f< Size; f++) { Sum += Family[f].HHincome; } return (Sum / Size); } void OverAvg(int Size, double Avg) { cout << endl; cout << left << setw(15) << "Family ID " << setw(10) << "Income " << setw(10) << "Number of people " << endl; for (int f = 0; f < Size; f++) { if (Family[f].HHincome > Avg) { cout <<left<<setw(15) << Family[f].Initials << setw(10)<< Family[f].HHincome << setw(25) << Family[f].Fam << endl; } } } double Poverty(int Size) { int Num = 0; for(int f= 0; f< Size; f++) { double Pov= 8000 + (500 * (Family[f].Fam - 2)); if(Family[f].HHincome < Pov) { Num++; } } return (Num * 100) / (double) Size; } void IncomeOrder(int Size) { int f; int h; for (f= 0; f< Size; f++) { for (h = 1; h < Size-f; h++) { if (Family[h-1].HHincome > Family[h].HHincome) { double temp = Family[h-1].HHincome; Family[h-1].HHincome = Family[h].HHincome; Family[h].HHincome = temp; string ID = Family[h-1].Initials; Family[h-1].Initials = Family[h].Initials; Family[h].Initials = ID; int FamMember = Family[h-1].Fam; Family[h-1].Fam = Family[h].Fam; Family[h].Fam = FamMember; } } } printOutput(Size); } void CalcPrintMedian(int Size) { double MedInc; if(Size % 2 != 0 ) { int Index = (Size / 2); MedInc = Family[Index].HHincome; } else { int Index1 = Size / 2; int Index2 = Index1 + 1; MedInc = (Family[Index1 - 1].HHincome + Family[Index2 - 1].HHincome) / 2; } cout << "The median income is $" << MedInc << endl; } int main() { int Size = 0; getData(Size); printOutput(Size); double Avg = AvgIncome(Size); cout << " The average income of all families totals to $" << Avg << endl << endl; cout << "Families earning more than the average income:" << endl; OverAvg(Size, Avg); double PovPercent = Poverty(Size); cout << "Families below the poverty line:" << fixed << setprecision(2) << PovPercent << "%"<< endl; cout << "In order of income:" << endl; IncomeOrder(Size); CalcPrintMedian(Size); }
WHVC 34000.00 5 AAAA 10500.00 8 BURB 23500.00 2 CCCC 15000.00 4 DATA 80000.00 3 EEEE 36000.00 5 FADE 8500.00 4 GATE 25000.00 1 HILO 3000.00 1 JURY 100000.00 5 KNEL 80000 4 LIST 41000.00 3 MEMM 5000.00 2 PQRS 18000.00 2 RELM 27500.00 4 SOLD 22100.00 2

Compiling Program...

Command line arguments:
Standard Input: Interactive Console Text

                

                

Program is not being debugged. Click "Debug" button to start program in debug mode.

#FunctionFile:Line
VariableValue
RegisterValue
ExpressionValue