Arrays: True or False. Checking each character array

I have a list of answers that will consist either of T (true) F(false0). I have written a function which has parameters of an array type variable. So here, this function will check each particular character under for loop and store it under youanswered. Furthmore, it will capitalize the letter too. It wil enter in the switch structure. If the user types in "T" it gets two points. If user types in "f" it gets one point. If user types in nothing. It gets zero points. I'm a litte fishy about my code. So would anyone please be able to look over my code and tell me if something needs to be worked on.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
void answerchecker(char answer[],int size, ofstream &out, int &correctpoints, int &wrongpoints, int &onepoint)
{
	int index=0;
	char youanswered;
	correctpoints=0;
	wrongpoints=0;
	onepoints=0;
	for (index=0;index<size;index++)
	{
		youanswered=answer[index]
		youanswered=(char)toupper(youanswered);
		switch (youanswered)
		{
			case 'T':
				correctpoints=correctpoints+2;
				break;
			case 'F':
				wrongpoints=wrongpoints+1;
				break;
			default:
				onepoint=onepoint+0;
		
		
		
		}
	
	}




}


Also. Not being asked to do it in this assignment. But suppose questions one to three are true. How can I add that into my code. Right now only thing my code does is that if the answer is true, it will add two points. So how can I structure this in that way. Just wondering :)
Can any forum members check this to see if this is correct please. I would highly appreciate it
I would make the distribution of points another function (easier to manage/modify).

At lines 10-11: when you use the operator[](unsigne int), it returns a reference to what is at that location (in this case, a character). Since, in this case, it is a character, treat is as such:

youanswered = toupper(answer[index]); would be more efficient (one less assignment operator, unless the compiler does somthing goofy I'm not aware of).

Also, make sure that you want the variables being passed to the function (which are passed by reference, I see you set them to 0) are correctly assigned int that function. Keep in mind that it will set them all to zero if nothing is done with them, and that they will modify what is in the calling function. If they are there for initialization purposes, you should remove them, ecause that should be handled propperly in the calling function.

One more thing: you don't use ofstream& out in this function at all! Why are you passing it as an argument?
Last edited on
Lol, I realized that too right now, so I would keep that in my mind to delete it. Thank you for your response :)
Topic archived. No new replies allowed.