Help with homework problem

The chess club of a high school is electing new president. Three club members are running: Andy, Brianna and Chuck. Write a program to do the following. Ask the user to enter the vote of each club member. Enter A for Andy, B for Brianna, C for Chuck, and E to exit. Count the number of votes each candidate gets. The user is free to use either uppercase or lowercase letters. If the user enters something other than A, B or C, don’t count that vote. Display the number of votes each candidate gets. Determine and display the outcome of the election. Notice that two or even all three candidates may tie for the first place. In cases like that, you need to display who they are. Example:

Enter A for Andy, B for Brianna, C for Chuck or E to exit: c
Enter A for Andy, B for Brianna, C for Chuck or E to exit: b
Enter A for Andy, B for Brianna, C for Chuck or E to exit: A
Enter A for Andy, B for Brianna, C for Chuck or E to exit: A
Enter A for Andy, B for Brianna, C for Chuck or E to exit: a
Enter A for Andy, B for Brianna, C for Chuck or E to exit: b
Enter A for Andy, B for Brianna, C for Chuck or E to exit: d
Enter A for Andy, B for Brianna, C for Chuck or E to exit: c
Enter A for Andy, B for Brianna, C for Chuck or E to exit: c
Enter A for Andy, B for Brianna, C for Chuck or E to exit: e
Number of votes for Andy: 3
Number of votes for Brianna: 2
Number of votes for Chuck: 3
Andy and Chuck tied for first place.
Press any key to continue . . .

#include <cstdlib>
#include <iostream>
using namespace std;

int main()
{

int Andy = 'A';
int Briana = 'B';
int Chuck = 'C';
int vote = ' ';

cout << "Enter A for Andy, B for Brianna, C for Chuck or E to exit:";
cin >> vote;



vote = toupper (vote);

while (vote != 'E')
{

if (vote =='A')
vote = vote +1;

else if (vote =='B')
vote = vote +1;

else if (vote =='C')
vote = vote +1;
}
cout<<"Number of votes for Andy:"<<Andy<<endl;
cout<<"Number of votes for Briana:"<<Briana<<endl;
cout<<"Number of votes for Chuck:"<<Chuck<<endl;


if ('A' > 'B' && 'A' > 'C')
cout << "Andy is the Winner" <<endl;

else if ('B' > 'A' && 'B' > 'C')
cout << "Brianna is the Winner" <<endl;

else if ('C' > 'A' && 'C' > 'B')
cout << "Chuck is the Winner" <<endl;

cout << "Enter A for Andy, B for Brianna, C for Chuck or E to exit:";
cin >> vote;






system("pause");
return 0;
}
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
#include <cstdlib>
#include <iostream>
using namespace std;

int main()
{

int Andy = 'A'; //what is the purpose of these three declarations?
int Briana = 'B';  // probably mean to use Andy, Briana, etc. to tally votes for each
int Chuck = 'C'; // but this only assures that you will cout << 'A','B','C' later
int vote = ' ';

cout << "Enter A for Andy, B for Brianna, C for Chuck or E to exit:";
cin >> vote; //putting this outside the while() loop that follows
                   // only allows you to enter one value for vote

vote = toupper (vote);
while (vote != 'E')
{ //you never change vote to 'E' in this loop, so it will never end if you enter anything but 'E'
// it will increment vote from A to B, B to C, C to D, then keep looping

if (vote =='A')
vote = vote +1;  //where do you intend to use vote?

// even if you move cin>> vote into this loop, vote is changed back to 'A','B','C' or 'E' 
//each time you make a new entry

else if (vote =='B')
vote = vote +1;

else if (vote =='C')
vote = vote +1;
}
// how would the values of Andy, Briana or Chuck be changed?
cout<<"Number of votes for Andy:"<<Andy<<endl;
// Andy was declared to be 'A' at the top, so the cout will read "Number of votes for Andy:A"
cout<<"Number of votes for Briana:"<<Briana<<endl;
cout<<"Number of votes for Chuck:"<<Chuck<<endl;


if ('A' > 'B' && 'A' > 'C') 
// 'A' will never be greater than 'B' or 'C'
cout << "Andy is the Winner" <<endl;

else if ('B' > 'A' && 'B' > 'C') 
cout << "Brianna is the Winner" <<endl;
//'B' is greater than 'A' but 'B' is never greater than 'C'

else if ('C' > 'A' && 'C' > 'B') 
cout << "Chuck is the Winner" <<endl;
//Chuck will always be the winner.

//do the next lines actually belong here?

cout << "Enter A for Andy, B for Brianna, C for Chuck or E to exit:";
cin >> vote;

system("pause");
return 0;
}

What you probably need to do is consider how you are going to add 1 to the correct member vote count each time you enter an a, b, or c. You'll need a variable for each one, maybe :
1
2
int Andy = 0;//. . .and later on, when Andy gets a vote:
if (vote = 'A') Andy ++;
Last edited on
1
2
3
4
5
6
7
8
9
10
11
-BEGIN
-declare variables for A,B and C
-while(input is not E)
	if(A)
		A++;
	if(B)
		B++;
	if(C)
		C++;
-print expected results
-END
Topic archived. No new replies allowed.