Skip to content

Instantly share code, notes, and snippets.

@AaronGoldsmith
Created November 21, 2016 01:17
Show Gist options
  • Select an option

  • Save AaronGoldsmith/4b3ffc3447cb9fafff95bcc074e04451 to your computer and use it in GitHub Desktop.

Select an option

Save AaronGoldsmith/4b3ffc3447cb9fafff95bcc074e04451 to your computer and use it in GitHub Desktop.
struct Matrix{
// you cannot initialize a variable ....
// ... (assign it values) inside the structure
int row1[3];
int row2[3];
int row3[3];
};
void printMatrixLine(int *row){
for(int i = 0;i<3;i++){
cout<<row[i]<< " ";
}
cout<<endl;
}
Matrix askForPoints(){
int x1,x2,x3;
int y1,y2,y3;
int z1,z2,z3;
cout<< " Type in 3 integers ";
cin >> x1 >> x2 >> x3;
cout <<" Type in 3 integers ";
cin >> y1 >> y2 >> y3;
cout << " Type in 3 integers ";
cin >> z1 >> z2 >> z3;
cout <<" --------- " << endl;
struct Matrix m = { {x1,x2,x3} , {y1, y2, y3} , {z1, z2, z3}};
return m;
}
int main(){
// initialize the matrix in main()
Matrix m = askForPoints();
printMatrixLine(m.row1);
printMatrixLine(m.row2);
printMatrixLine(m.row3);
// then pass in the initialized matrix into printMatrix()
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment