By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
425,929 Members | 634 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 425,929 IT Pros & Developers. It's quick & easy.

question about labeling entry data

P: 2
I have to create a 2 dimensional array (5X4 (int type)) which can hold 4 exam scores for each of 5 students.Here is my code:

#include<stdio.h>

int main(void)
{
int numstu = 5;
double studentscore[numstu][5];
double score1, score2, score3, score4;
int i, z;
double avgstu;
double avgexam = 0;
double sum = 0;
for(i = 0; i < 5; i++){
printf("Please input 4 exam scores for student %d: ", i+1);
scanf("%lf%lf%lf%lf", &score1, &score2, &score3, &score4);
studentscore[i][0] = score1;
studentscore[i][1] = score2;
studentscore[i][2] = score3;
studentscore[i][3] = score4;
avgstu = (score1 + score2 + score3 + score4) / 4.0;
studentscore[i][4] = avgstu;
printf("Average score for student %d is: %lf\n", i+1, avgstu);
}
for(z = 0; z < 4; z++){
for(i = 0; i < 5; i++){
avgexam += studentscore[i][z] / 5;
}
printf("Average exam %d is: %lf\n", z+1, avgexam);
avgexam = 0;
}
return 0;
}
Now I a asked to write a function that will output the entry data appropriately labeled, for example:

Student Data

Exam 1 Exam 2 Exam 3 Exam 4
1 75 82 66 87
2 69 59 72 77
3 66 87 77 62
4 80 57 91 93
5 94 86 88 96

Can someone please give me a hint of how to do that? I have no idea how to start.
Dec 6 '11 #1
Share this Question
Share on Google+
1 Reply


weaknessforcats
Expert Mod 5K+
P: 9,197
First, you say you need an array of int but you have coded and array of double.

Second, read this: http://bytes.com/topic/c/insights/77...rrays-revealed

Third, write a function that can display one row of your array.

Fourth, write a loop in main() that passes each eement of your array to the function you just wrote.
Dec 6 '11 #2

Post your reply

Sign in to post your reply or Sign up for a free account.