I am trying to use an increment counter in a while loop for multiple selections and my counter for the first expression entered is incrementing correctly, it is off by one. All other enteries are counted correctly.
I am also trying to count the total number of enters made and this counter is off by 2
any help would be greatly appriciated.
[code]
//This program tally a survey on beverages
#include <iostream>
using namespace std;
int main()
{
int number,choice,
person = 1 ;//Number of people taking survey
int sum1counter = 0,//Coffee
sum2counter = 0,//Tea
sum3counter = 0,//Coke
sum4counter = 0;//Orange Juice
cout << "Please input the favorite beverage of person #" << person++ << ": \n";//Increment the number of people in the survey
cout << "Choose 1, 2, 3, or 4 from the above menu or -1 to exit the program." << endl;
cin >> choice;
cout << "Please input the favorite beverage of person #" << person++ << ": \n";//Increment the number of people in the survey
cout << "Choose 1, 2, 3, or 4 from the above menu or -1 to exit the program." << endl;
cin >> choice;
}
cout << "The total number of people survery is " << person -2 << ". The results are as follows:" << endl;//Needed to correct the person running total with a -2
cout << "Beverage Number of Votes" << endl;
cout << "***********************************" << endl;
cout << endl;
cout << "Coffee " << sum1counter << endl;
cout << "Tea " << sum2counter << endl;
cout << "Coke " << sum3counter << endl;
cout << "Orange Juice " << sum4counter << endl;
cout << endl;
The reason you need to reduce the number of people by two was that your program was counting the person who entered "-1" as a person entering their favorite drink and you started the person count at 1 instead of zero.