Hi everyone,
I need some help for an assignment...I have completed the program and it all works, however for a previous (easier) assignment I created the program all in main then removed parts and created functions to make the program more desirable. I am trying to do it for this assignment which basically multiplies 2 matrices and outputs the resultant, but it is proving rather difficult.
Firstly, I'd like to make a function for the chk statement in my program as below;
Code:
int main (void){
int MXA[4][4], MXB[4][4], MLT[4][4], RowA, ColA, RowB, ColB;
int i, j, k;
char vld[80], c;
int chk;
/* Intro */
printf(" Matrix Multiplier\n");
printf(" _________________\n");
printf("\n Welcome to the Matrix Multiplier. This program is designed to output \n the result of multiplying two, 4 X 4 matrices.\n");
printf("\n_______________________________________________________________________________\n");
/*END Intro */
/*Matrix A*/
printf("\n Create Size of Matrix A [MAX 4 X 4 Matrix]:\n");
do {
printf("\n Number of Rows [R] = ");
gets(vld);
chk = sscanf(vld, "%d",&RowA);
if (chk != 1)
{ printf ("\n ERROR; You have entered a character. Please Enter a number!\n"); }
else
if (RowA < 0 || RowA > 4)
{ printf ("\n You have entered a number out of range.\n Please re-enter!\n"); }
} while (RowA < 0 || RowA > 4);
do {
printf("\n Number of Columns [C] = ");
gets(vld);
chk = sscanf(vld, "%d",&ColA);
if (chk != 1)
{ printf ("\n ERROR; You have entered a character. Please Enter a number!\n"); }
else
if (ColA < 0 || ColA > 4)
{ printf ("\n You have entered a number out of range.\n Please re-enter!\n"); }
} while (ColA < 0 || ColA > 4);
/*End Matrix A*/
The chk statement makes the program more robust as to warn the user that a character has been entered. However, as you can see I have used it twice here, and a few more times in the rest of the program although I haven't shown it here. I'd like to make this a function so its cleaner in main. I have tried various ways but no luck at all.
So basically, I'd like to chk loop bit to be in a function and call upon this function when I need it.
Any help would be appreciated!!
Thank you!