I want to build a program for my c language project.What i need to do is that the user should enter the number of students,number of questions,correct answers,each students answers answers and then the program should calculate the number of correct answers,and their standing,the most wronged question . the problem i am facing is that i dont know how to match each students answers with the correct answer.this has to be done with dynamic arrays. Help me in this: I am posting the code.

#include<stdio.h>
#include<conio.h>
#include<stdlib.h>


int main (void)
{
	int studnum,a,b;
	int quesnum;
	int *array1;
	int *array2;
	int *correctanswers;
		
	printf("Plz enter the number of students: ");
	scanf("%d",&studnum);

	
	printf("Plz enter the number of questions: ");
	scanf("%d",&quesnum);
	
	correctanswers = (int*) malloc(quesnum*sizeof(int));
	array2 = (int*) malloc(quesnum*sizeof(int));
	array1 = (int*) malloc(studnum*sizeof(int));
	
	printf("Plz enter the correct answers: ");
	for(a=0;a<quesnum;a++)
	{
		printf("Q%d-",a+1);
		scanf(" %c",&correctanswers[a]);
		
	}
	
	for(a=0;a<studnum;a++)
{
		printf("Enter student ids: ");
		scanf("%d",&array1[a]);
		for ( b=0;b<quesnum;b++)
		{
			printf("Enter questions answers:");
			printf("#%d.",b+1);
			scanf(" %c",&array2[b]);
		}
}	
	


	getche();
	return 0;
}

the problem i am facing is that i dont know how to match each students answers with the correct answer.this has to be done with dynamic arrays. Help me in this:

Compare each of the values using a loop

As for all the students

You could initialize the student and their corresponding answers using a multidimensional array... it makes it a lot easier

a = (int **)malloc(sizeof(int *) * row); //where row is the number of students
                for(x=0; x<row; x++)/*for row 1 to last number of student*/
                        *(a+x)=(int *)malloc(sizeof(int) * col);
/*create another set of arrays for their answers depending on the number of students*/

Compare each of the values using a loop

As for all the students

You could initialize the student and their corresponding answers using a multidimensional array... it makes it a lot easier

a = (int **)malloc(sizeof(int *) * row); //where row is the number of students
                for(x=0; x<row; x++)/*for row 1 to last number of student*/
                        *(a+x)=(int *)malloc(sizeof(int) * col);
/*create another set of arrays for their answers depending on the number of students*/

I have done a thing that i have initialized an array of [100][100] and this has made my work a lot easier. Still the problem i am facing is that how to evaluate the standing of students with their id's in the descending order e.g student id 07 has got topped the exam and then how to give the feedback on the most frequently missed question.

I have done a thing that i have initialized an array of [100][100] and this has made my work a lot easier. Still the problem i am facing is that how to evaluate the standing of students with their id's in the descending order e.g student id 07 has got topped the exam and then how to give the feedback on the most frequently missed question.

I suggest you make another array that has the same size as the number of questions, here you will store the number of times a student makes a mistake on a particular number

how to evaluate the standing of students with their id's in the descending order

Either add one more space to the answers array of each student or make a separate array where you will store the total score of each student so you can compare them

I suggest you make another array that has the same size as the number of questions, here you will store the number of times a student makes a mistake on a particular number


Either add one more space to the answers array of each student or make a separate array where you will store the total score of each student so you can compare them

Ok i have done finding how many times does a particular question is being missed by the students.Now the problem i m facing is that i know how to sort the results but i dont know how to show the results with their ids or students number. e.g student #2 is #1 in the class and so on in descending order. i would highly appreciate if u could plz clarify it with the help of code.

Ok i have done finding how many times does a particular question is being missed by the students.Now the problem i m facing is that i know how to sort the results but i dont know how to show the results with their ids or students number. e.g student #2 is #1 in the class and so on in descending order. i would highly appreciate if u could plz clarify it with the help of code.

Could you post your current code it's hard to guess if I don't know what you did so I'll just post a guide

int total=0; //starting student in the arraylist
while (total<=100){ //number of students
      if(student[total]<student[total+1]) //if current value(student score) is less than the next value
{
 //code here that will exchange values of current array index with its next
total = 0; //start again
}
total++; // increment to next index
}

umm... ok... Its pretty simple... All u gotta do is search ur original array of each student for correct no. of answers!

For eg: Student 2 got 8 correct and is #1
Student 3 got 7 correct and is #2

Since u know their positions and u have the sorted array in order of marks.. Tally the marks with the student no.

Eg: In the above example, u know the person who is #1 has 8 answers correct and #2 has 7 correct. Also, u know the person who has 8 correct is student 2 and who has 7 correct is student 3. So, check the marks of the sorted array with the marks of the preexisting array with the student nos!

P.S- also to prevent overwriting of same person... i.e if two people have same no. of correct answers - student7 and student8 have 3 correct answers.. After u have found student7, change the value of correct answers to some unusable value which will never show up.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.