program not adding right...please help

I am in my first month of programming o be kind. I am taking at .txt and using its data to complete survey. It is adding an extra male and I do not know why.
Last edited on
Well, from counting the data that you gave us, it looks as if you do have 5 males.
Im sorry, i miss typed. it needs to be 7 females. the males are correct
1
2
3
4
else  {
		
			countFemale++;
		}


Would be wise to change this to else if(gender == 'F')

I have a feeling that's where the issue is coming in at. Basically, if your file does not have an 'M' as the second entry per line, it's going to add one to the female count. What if someone made a mistake and did 'm'? It would add another female

EDIT:
Should do the same for college
Last edited on
Thank you for your response, I tried you suggestion and still have same result. All my ELSE statement are where my arithmetic is going wrong. All the IF ones are doing what they are supposed to.

Last edited on
Your problem is that for some reason your loop happens 13 times instead of 12 it is supposed to, so in the 13th it has the same values as in the 12th

If you check the averages by yourself you see it

P.S: no idea why this is happening sorry

EDIT: check this thread it is your exact problem and a brief explanation on why the extra loop and how to fix http://www.cplusplus.com/forum/beginner/70565/
Last edited on
Even if it loops through an extra time, it shouldnt add any to the count. Unless it is reading a line twice. Put a cout in each if block and just have it print out whatever it found. You should be able to catch whatever is happening that way
Thank you guys! @ccsdude this was my friends solution who I worked on this with. The fix on the page worked!
Thank you!
Topic archived. No new replies allowed.