Click here to Skip to main content
15,949,686 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
this is multiple quiz, when user enter answer at end of the quiz if more than 15 wrong
Show
Failed with (..) incorrect answer
       Incorrect question: 14,15,12,.....,


but what i have post only shows
Failed with 7 incorrect answer


What I have tried:

C#
int[] usercount = new int[20];
            int count = 0;
            int rightanswer = 0, wronganswer = 0;
            foreach (char answer in useranswers)
            {
                if (char.ToUpper(answer) == char.ToUpper(CorrectAnswer[count]))
                {
                    rightanswer++;
                }
                else
                {
                    wronganswer++;
                }
                count++;
            }
            if (rightanswer >= 15)
            {
                Console.WriteLine("Passed with {0} correct answers! You are amazing!", 
                                rightanswer);
            }
            else
            {
                Console.WriteLine("Failed with {0} incorrect answers", wronganswer);
            }
Posted
Updated 8-Apr-18 14:12pm
v2

The first thing you need to do is store a list of which questions he got wrong ... you don't do anything with that at present, so have a think about what collections you know how to use, and decide what you want to store them in.

Then use that inside the if block so you can print it later.

But... this is your homework, and we don't know what you have been taught s far, so I'll give you no code!

Give it a try, and see how far you get - this really isn't complicated if you think about it for a few minutes.
 
Share this answer
 
Comments
Member 13757304 8-Apr-18 16:52pm    
i try but not working
OriginalGriff 8-Apr-18 17:38pm    
What did you try?
How is it "not working"?
What does it do that you didn't expect, or not do that you did?
What did you do you find out why?
Show the relevent code fragment.
Quote:
but what i have post only shows Failed with 7 incorrect answer

Because the part that show the list of incorrect answers is missing in your code.
1) you need to choose where to add the code for list of incorrect answers.
2) Just as you checked each answer to count correct and incorrect, you have to check them again and print the number of each incorrect ones.

C#
foreach (char answer in useranswers)

Advice: Never use a for each loop to scan 2 arrays, it only makes code harder to read and do not save the counter of the loop, you handle it by yourself manually.
In this case a for loop will make obvious that you are matching the same positions of both variables.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900