So I'm writing a function to compare two strings of letters from a scantron. Example: aaaaaaaAbbbBaccCdaaaaaaaa would be the teachers answer key and aaaaaaaabBBBacccdabaacaaa would be a students answers. Capitals and Lower Cases are equal.
At the moment all its returning are zeros, so I'm guessing something I've done isn't allowed.
1 2 3 4 5 6 7 8 9 10
int GetGrade(string TeacherKey, string StudentKey)
{
int Correct=0, Grade;
for (int i=0; i<25; i++)
if (TeacherKey[i] == StudentKey[i] || TeacherKey[i] == StudentKey[i] + 32){
Correct++;
}
Grade = Correct/25*100;
return Grade;
}
The type of Correct is an int, which doesn't support floating point numbers (decimals). If correct is below 25, after the division with 25 the prog truncates the numbers following the decimal, leaving you with 0.
That worked and got me closer, but now all the numbers are very slightly off =/. I'm guessing it has something to do with how I calculated lower cases and capitals being the same because when I tested It I used
aaaaaaaAbbbBaccCdaaaaaaaa Answer key
aaaaaaaAbbbBaccCdaaaaaaaa Copy and Pasted answer key 100% score
AAAAAAAAbbbbacccdaaaaaaaa Variations in capitals 92% score
They were both supposed to be 100%.