I have an application that asks the user a set of questions and then receives answers to those questions and then stores them. I also have a problematic line of code where the console returns statistics on the user. I've tried to make the console write out how many correct questions and how many incorrect ones the user answered, but making the word "question" singular when said amount is one, and plural when it is above one. Following, is the line of code I have written, although I receive the error that is written in the title:
Console.WriteLine (
"You have answered {0} question{1} correctly and {2} question{3} incorrectly.",
correctCount1,
correctCount1 > 1 || correctCount1 == 0 ? "s" : incorrectCount1,
incorrectCount1 > 1 || incorrectCount1 == 0 ? "s" :);
I strongly suspect that this:
correctCount1 > 1 || correctCount1 == 0 ? "s" : incorrectCount1
should be:
correctCount1 > 1 || correctCount1 == 0 ? "s" : "", incorrectCount1
After all, you don't really want it to say:
"You have answered 5 question10"
do you?
Likewise for the final argument, this:
incorrectCount1 > 1 || incorrectCount1 == 0 ? "s" :
should be:
incorrectCount1 > 1 || incorrectCount1 == 0 ? "s" : ""
You always need to provide three operands to the conditional operator.
See more on this question at Stackoverflow