i want to know how to stored name and numbers in arrays? i mean, how to write the codes?
because i want to write an entry system for students' marks.
need help.
tq
i mean, how to write the codes?
With a text editor.I doubt anyone will do your homework for you, but I've been proven wrong before.
hmm... int arr[10] = { 0 }; // 0-9 elements arr[0] = some_val; ... arr[9] = some_val; scanf("%d", &arr[desired_index]); // dangerous approach or cin >> arr[desired_index]; // dangerous approach
Strings a bit different depending on if they're c-style strings or cpp's string class.char str[2][80] = { "", "" }; strcpy(str[0], "some string"); fgets(str[0], sizeof str[0], stdin); // side effect of leaving '\n' but safe cin >> str[0]; // side effect breaks on white space cin.getline(str[0], sizeof str[0], '\n'); or string s[2] = { "", "" }; s[0] = "some string"; cin >> s[0]; // side effect breaks on white space getline(cin, s[0], '\n');HTH
-------------------------------------------
I have no aspiration for preaching. ;-)
Mark system
enter mark for:
jose : 99
max : 87
ian : 77grade report
name no mark grade
jose 02 99 A
max 01 87 A
ian 09 77 B-analysis:
Average mark : ...
highest mark : .....
lowest mark : .....
A: ...%
A-: ...%
B: ....%
....above is the output.
Q: the coding? or any idea to write the code?** i know i must use array, but i don't know how to store the mark input by user into the name listed..
smbdy help me..
I'd use structured data myself. typedef struct { char name[80]; int grades[MAX_GRADES]; char lettergrade; } students; students records[MAX_STUDENTS];If you need to use the static arrays, declare 2D arrays
int grades[MAX_STUDENTS][MAX_GRADES]; char names[MAX_STUDENTS][80]; char letter[MAX_STUDENTS];storing would be
for(int i = 0; i < MAX_STUDENTS; i++) { cin.getline(names[i], sizeof names[i]); for(int j=0; j < MAX_GRADES; j++) { cin >> grades[i][j]; } }where i is the index of the current student and j is the index of the current grade for student[i]
You need a dimension for the total number of students in order to keep the records in order.
HTH
-------------------------------------------
I have no aspiration for preaching. ;-)
btw.
i have to use C language.
i not yet learn C++. huhu
tq :)
replace cin with fgets and you're all set. for converting the numbers, try sscanf char nbuf[10]; ... // code fragment from above for(j = 0; j < MAX_GRADES; j++) { do { // output grade message fgets(nbuf, sizeof nbuf, stdin); } while((sscanf(nbuf, "%d", &grades[i][j])) != 1); }The names are similar...
fgets(names[i], sizeof names[i], stdin);gravy no??
HTH
-------------------------------------------
I have no aspiration for preaching. ;-)
probs here. need some help! if(mark[i] >= 85)
{
grade[0]='A';
count++;
}
else if(mark[i] >= 80)
grade[i]='A';
else if(mark[i] >= 75)
grade[i]='A-';
else if(mark[i] >= 70)
grade[i]='B+';
else if(mark[i] >= 65)
grade[i]='B';
else if(mark[i] >= 60)
grade[i]='B-';
else if(mark[i] >= 55)
grade[i]='C+';
else if(mark[i] >= 50)
grade[i]='C';
else if(mark[i] >= 0 && mark[i] < 50)
grade[i]='E';
}printf("%d.%s\t\t%d\t%d\t%c\n", i+1, name[i], matric[i], mark[i], grade[i]);
i try to print out the character A-. but it only print - sign
what should i do with it?1 more;
i don't know how to calculate the % of grades? any suggestions/formula?
grade[index] = 'A-' will not work because you are trying to store two characters when there is space for one. if you want to do that, declare char grade[MAX_STUDENTS][3], and then use strcpy(grade[i], "A-"); or whatever is appropriate.
do you mean each student's grade average? if so, (mark[STUDENT_INDEX][0] + mark[STUDENT_INDEX][1] + mark[STUDENT_INDEX][n_number_of_marks - 1]) / n_number_of_marks. If not, then you'll need to clarify a bit.
HTH
-------------------------------------------
I have no aspiration for preaching. ;-)
Yes (14) | ![]() | |
No (14) | ![]() | |
I don't know (15) | ![]() |