While loop not exiting right after

I am having trouble when trying to exit. if i type -1 it still asks me "Enter gender" which I enter -1 again...which shouldn't happen ...if there's any way to not make this happen?
and also my smallest [for trying to find the smallest number] gives me -1. everything else works. Help would be much appreciated. :]

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
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
#include <iostream>
using namespace std;

int main ()
{
	int attendeeAge = 0;
	int count1 = 0, count2 = 0, count3 = 0, count4 = 0, count5 = 0;
	int sumAttendee = 0, count = -1;
	int smallest = 0 , largest = 0;
	char gender;
	int countM = 0, countF = 0;


	do
	{
		cout << "Enter age of attendee (negative number to quit): ";
		cin >> attendeeAge;
		cout << "Enter gender (M or F): " ;
		cin >> gender;

		smallest = attendeeAge;
		count++; 

		if(attendeeAge < 0)
			smallest = attendeeAge;

		if(attendeeAge > largest)
			largest = attendeeAge;


		sumAttendee = sumAttendee + attendeeAge ;
		
		if(attendeeAge > 0 && attendeeAge <= 18)
			count1++;
		if(attendeeAge >= 19 && attendeeAge <= 30)
			count2++;
		if(attendeeAge >= 31 && attendeeAge <= 40)
			count3++;
		if(attendeeAge >= 41 && attendeeAge <= 60)
			count4++;
		if(attendeeAge >= 60)
			count5++;

		if(gender == 'M')
			countM++;
		if(gender == 'F')
			countF++;

	} while (attendeeAge >= 0);

	cout << "\nAge 0  to 18: " << count1 << endl;
	cout << "Age 19 to 30: " << count2 << endl;
	cout << "Age 31 to 40: " << count3 << endl;
	cout << "Age 41 to 60: " << count4 << endl;
	cout << "over 60: " << count5 << endl << endl;

	cout << "Males: " << countM << endl;
	cout << "Females: " << countF << endl;
	cout << "the average age was " << (sumAttendee+1) / count << endl;
	cout << "the youngest person in attendance was " << smallest << endl; 
	cout << "the oldest person in attendance was " << largest << endl; 
	return 0;
}


Enter age of attendee (negative number to quit): -1
Enter gender (M or F): -1

Age 0  to 18: 0
Age 19 to 30: 0
Age 31 to 40: 0
Age 41 to 60: 0
over 60: 0

Males: 0
Females: 0
Press any key to continue . . .


Enter age of attendee (negative number to quit): 12
Enter gender (M or F): F
Enter age of attendee (negative number to quit): 68
Enter gender (M or F): M
Enter age of attendee (negative number to quit): 23
Enter gender (M or F): M
Enter age of attendee (negative number to quit): 21
Enter gender (M or F): F
Enter age of attendee (negative number to quit): 24
Enter gender (M or F): F
Enter age of attendee (negative number to quit): -1
Enter gender (M or F): -1

Age 0  to 18: 1
Age 19 to 30: 3
Age 31 to 40: 0
Age 41 to 60: 0
over 60: 1

Males: 2
Females: 3
the average age was 29
the youngest person in attendance was -1
the oldest person in attendance was 68
Press any key to continue . . .
The check to stop the loop happens at the END of each loop. The entire loop is run through, and THEN the condition is checked. Setting the condition to exit at the start of the loop will not make it jump to the end of the loop. The entire loop will be gone through and THEN the condition will be checked.
Topic archived. No new replies allowed.