Try adding this line to your program
while ((ch = cin.get()) != '\n'){}
and read this link to find out what's going on
http://www.daniweb.com/forums/thread90228.html
#include <iostream>
#include <string>
using namespace std;
int main()
{
string *name;
// int *votes;
int i;
int numVotes;
char ch;
cout << "how many voters: ";
cin >> numVotes;
name = new string[numVotes];
while ((ch = cin.get()) != '\n'){}
for(i = 0; i < numVotes; i++)
{
cout <<"enter canidates last names: ";
getline(cin,name[i]);
}
for(i = 0;i < numVotes; i++)
{
cout << name[i] << endl;
}
return 0;
}
gerard4143
Nearly a Posting Maven
2,272 posts since Jan 2008
Reputation Points: 512
Solved Threads: 387