I currently am having a problem regarding strings and character arrays. What I want to do is have a user type a string like "Johnson 5000" (using cin, not from an input file or preset string), and I want to store this input into two parallel arrays. One for characters while the other is for values. Assume that all variables are properly declared.
for (int canidateNum = 0; canidateNum < ROWS; canidateNum++)
{
cout << "Canidate #" << canidateNum + 1 << ": ";
cin >> name[canidateNum] >> voteNum[canidateNum];
}
cout << name[0] << " " << voteNum[0] << endl;
...
However, upon entering something like "Johnson 5000" in the program, it will output the wrong result, displaying J and not 5000. I tried using various methods of inputing a string into a character array, but to no avail. I tried multi-dimensional arrays, but that didn't work for me either (probably did it wrong).
Can anyone assist me in this?
2007-11-18
19:05:47
·
5 answers
·
asked by
Anonymous
in
Computers & Internet
➔ Programming & Design