Quick question... Structs & Arrays.
Hi everyone. I am working on making a program that deals with household surveys. I am still learning C++ and my first time dealing with more than one array. Here is the problem:
Write a program to read these survey results. Each record contains data for one household, including a 4-digit integer id number, the annual income, and number of household members. Max of 25 households. Write a program to read the results into 3 arrays.
It sounds to me like I need to use a struct.. but I'm not sure. Here is how I think it should be written...
Code:
#define MAX_SIZE 25
#include
struct household{
int id[size];
int income[size];
int members[size];
};
void readStruct(household&, int&);
void displayStruct(household stuhousehold, int);
int main(){
int size = 0;
struct household value;
household info;
readStruct(household, size);
displayStruct(household stuhousehold, size);
return 0;
}
void readStruct(household& oneHouse, int& size){
int i = 0;
cout << "Enter the four-digit integer identification number: ";
cin >> household id;
cout << "Enter the annual household income: ";
cin >> household income;
cout << "Enter the number of household members: ";
cin >> household members;
while(members > 0 && i < MAX_SIZE) // I was trying to count # of households with i.
}
void displayStruct(household stuhousehold, int n){
cout << setw(28) << "Identification Number" << setw(28) << "Annual Income" << setw(28) << "Household Members" << endl;
for(int i=0; i<n; i++)
for(int j=0; j<n; j++)
for(int k=0; k<n; k++)
cout << setw(28) << stuhousehold.id[i] << setw(28) << stuhousehold.income[j] << setw(28) << stuhousehold.members[k] << endl;
}
I think I messed up. I'm kind of confused so if anyone knows of a good website or something to help explain arrays and structs, let me know. Thank you.