Hi I am trying to do a homework problem but this is about as far as i have gotten. need some help if you will. also am a complete novice so would like it if you explained in baby terms :) Sorry...

am trying to solve this problem...
You have been asked to construct a program that will assist in grading multiple choice exams.
Prompt the user for the number of questions up to 20.
Prompt the user for the correct answer to each question as a letter(char fom A-E).
Store this information in an answer key.
Prompt the user for the number of students in the class up to 50.
For each student in the class, prompt the user for a student ID(int) and the students answer to each question(char).
Finally, grade the exams and store the results(int).
Find the average, high and low scores and output the results.

Hint: You will need several arrays to store all of the information:
1) An array of char to hold the answer key
2) An array of int to hold the student ID's
3) A 2D array of Char to hold the answers
4) An array of int to hold the scores

EXAMPLE INPUT/OUTPUT:

Enter number of Questions: 2
Enter the correct answer for Question 1: A
Enter the correct answer for Question 2: B

Enter number Students in the class: 2

Enter the Student ID for for student 1: 12345
For Student 12345, Enter the answer to Question 1: A
For Student 12345, Enter the answer to Question 2: B

Enter the Student ID for for student 2: 54321
For Student 54321, Enter the answer to Question 1: A
For Student 54321, Enter the answer to Question 2: A

``````Results
======================================================
Student ID      Score
12345          2/2
54321          1/2
======================================================
High Score = 2/2
Low Score  = 1/2
Average    = 1.50
``````

my code so far... (is probably completely wrong)

``````#include <iostream>
using namespace std;

const int maxquestions=20;
const int maxstudents=50;

void output();

void main()
{
char key[maxquestions];
int numquestions, numstudents;
int studentid;
int scores;

system("pause");
}
{
cout << "Enter number of questions: ";
cin >> numquestions;
for(int i=0; i<numquestions; i++)
{
cout << "Enter correct choice for question " << i+1;
cin >> key[i];
}
}
{
cout << "Enter number of students in the class: ";
cin >> numstudents;
for(int student=0; student<numstudents; student++)
{
cout << "Enter the student id for the student " << student+1 << ": ";
cin >> studentid[student];
for(int index=0; index<numquestions; index++)
{
cout << "For student " << studentid[student] << ", Enter the answer to question " << index+1 << ": ";
}
}
}
{
for(int student=0; student<numstudents; student++)
for(int question=0; question<numquestions; question++)
{
scores[student]++;
}
}
``````

## All 3 Replies

Welcome to Daniweb!

First, please use code tags around your code, it makes it much easier for us to read. Second, I STRONGLY recommend that you use std::vector instead of c-style arrays. It will save you hours of headaches for sure.

Good luck,

Dave

Firstly 'void main' and 'system("pause");' are BAD programming practices use 'int main' and 'cin.get()' instead .

Anyways here is your code wrapped in CODE tags

``````#include <iostream>
using namespace std;

const int maxquestions=20;
const int maxstudents=50;

void output();

void main()
{
char key[maxquestions];
int numquestions, numstudents;
int studentid;
int scores;

system("pause");
}
{
cout << "Enter number of questions: ";
cin >> numquestions;
for(int i=0; i<numquestions; i++)
{
cout << "Enter correct choice for question " << i+1;
cin >> key[i];
}
}
{
cout << "Enter number of students in the class: ";
cin >> numstudents;
for(int student=0; student<numstudents; student++)
{
cout << "Enter the student id for the student " << student+1 << ": ";
cin >> studentid[student];
for(int index=0; index<numquestions; index++)
{
cout << "For student " << studentid[student] << ", Enter the answer to question " << index+1 << ": ";
}
}
}
{
for(int student=0; student<numstudents; student++)
for(int question=0; question<numquestions; question++)
{
scores[student]++;
}
}``````

What exactly is the problem you are facing.
1. Avoid void main(), it's non-standard.
2. Avoid system() calls, since they are worthless & slow
3. Also I recommend you use a class for this.

``````class Student
{
int id;