PROGRAMMING IN C: I have a set of student ID numbers stored in a two column arra
ID: 674525 • Letter: P
Question
PROGRAMMING IN C:
I have a set of student ID numbers stored in a two column array
ex: studentID[3][2]={{11111111, 1}, {2222222, 1} {3333333, 2}
with the first column being the student ID number and second column being the type of student. I want to check the student ID the user entered to make sure it matches a student id within my array. right now in my program, if the user enters 11111111, it will say it's an invalid ID number (but it's actually valid?) Heres the code i have for it:
int checkID(int stuInfo[6][2], int idEntered) {
int i=0;
int j=0;
int row=6;
int col=2;
for(i=0;i
for(j=0;j
if(stuInfo[i][j]==idEntered) {
return j;
}
else {
return -1;
}
}
}
return -1;
}
what am i doing wrong????
Explanation / Answer
Here is the code which works corrrectly for you.....
#include <stdio.h>
int checkID(int stuInfo[3][2], int idEntered) {
int i=0;
int row=3;
for(i=0;i < row; i++)
if(stuInfo[i][0]==idEntered)
return 1;
return -1;
}
int main()
{
int key;
int studentID[3][2]={{11111111, 1}, {2222222, 1}, {3333333, 2}};
printf("Enter the student ID to check with: ");
scanf("%i", &key);
if(checkID(studentID, key) != -1)
printf("Found. ");
else
printf("Not Found. ");
}
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.