[//This program collects survey data from a few people and displays results
#include <iostream>
# include <string>
#include <iomanip>
usingnamespace std;
int main()
{
int coffee = 0,
tea = 0,
coke = 0,
juice = 0,
person = 1,
choice = 0;
string statementA = "Please input the favorite beverage of person # ",
statementB = "\nChoose 1,2,3 or 4 from the above menu or -1 to exit the program.";
while (choice != -1)
{
//Display the drink survey and get a choice.
cout << "Soft Drink Survey\n"
<< "1. Coffee\n"
<< "2. Tea\n"
<< "3. Coke\n"
<< "4. Orange juice\n"
<< "5. Please enter -1 to exit.\n\n"
<< statementA << person << statementB << "\n";
cin >> choice;
person = person++;
}
switch (choice)
{
case 1:
coffee = (coffee ++);
break;
case 2:
tea = (tea ++);
break;
case 3:
coke = (coke ++);
break;
case 4:
juice = (juice ++);
break;
}
cin.get();
if (choice = -1)
{
cout << "\n\nThe total number of people surveyed is " << (person - 2) << ". The results are as follows:\n";
cout << "Beverage of choice and votes.\n";
cout << "*******************************\n";
cout << "Coffee = " <<coffee << endl;
cout << "Tea = " <<tea << endl;
cout << "Coke = " << coke << endl;
cout << "Orange juice = " << juice << endl;
}
cin.get();
return 0;
}
Your while loop ends at line 33, therefore your switch statement is only executed once you exit the while loop.
Your syntax for incrementing variables is odd. You can increment a variable simply by:
person++;
Line 52: You're using the assignment operator (=), not the equality operator (==). In fact, this if statement is unnecessary.
PLEASE USE CODE TAGS (the <> formatting button) when posting code.
It makes it easier to read your code and also easier to respond to your post. http://www.cplusplus.com/articles/jEywvCM9/
Hint: You can edit your post, highlight your code and press the <> formatting button.
Ok I changed the person++ and the == I still get the same result Everything works fine exept it just wont give me the tally of the choices. It keeps track of the people survayed but the numbers come up as all zeros.