问题描述:

I have program in C.

Assume teacher has engaged you as a software consultant to write a program that would help lecturers speed up their marking of multiple choice questions. For this program you are required to do prototype program to mark question papers consisting of 10 multiple choice questions using the C programming language.

Each question has four choices a, b, c and d. The lecturer is required to look at the student's answer sheet and enter answers (a, b, c and d)

one by one. The C program must compare the answer with the solution, output a / if the answer is correct, an x if it is incorrect, and the program must then compute the mark obtained out of a total of 10 marks.

Example.

question 1: a/

question 1: bx

Assume the answers are (a, b, c, d, a, b, c, d, a, b) respectively and I have to ask the user to press y to loop again and n to exit the loop.

z='y','n';

while (z=='y')

{

while ( count<10)

{

printf("\n question #%d:",count+1);

r=getch();

while(r!='a' && r!='b' && r!='c' && r!='d')

{

r=getch();

}

putch(r);

if (r==answer[count])

{

putch('/');

mark=mark+1;

}

else

{

putch('x');

}

count++;

}

}

printf("\n\n the mark is: %d / 10", mark);

printf("\n\n continue? (y / n)");

z=getch();

printf("\n\n ");

system("pause");

return(0);

网友答案:

You must enclose everything in another loop that should break when the user inputs 'n'.

Something like:

bool finished = false;
while (!finished) {
  // reset status of variables
  while (count < 10) {
    // your actual code
  }

  finished = /* users typed y or n */
}
相关阅读:
Top