Because
correctAnswers
and
totalQuestions
are integers,
correctAnswers / totalQuestions
will also return an integer value. And since
correctAnswers
can never be greater than
totalQuestions
the division can only ever return 0 or 1!
You could try doing this:
string correctAnswerPercentage = (correctAnswers * 100 / totalQuestions).ToString("00%");Or this:
string correctAnswerPercentage = ((float)correctAnswers * 100.0 / (float) totalQuestions).ToString("00.0%");