I want to write a program that allow the console to take in any number of names, and then output the names and the number of names input. The problem is, I want to do this in a while loop, but for some reason, I can't get it to work with strings. Any ideas?
As shadowCODE said, you need to check if the LAST element entered is "Exit" instead.
1 2 3 4 5
while (counter > 0 && signature[counter-1] != "Exit"){
cout << "Please input your electronic signature: ";;
cin >> signature[counter]; // You never increment i
counter++; // But you increment counter
}
or if you dislike that extra counter > 0 check
1 2 3 4 5
do {
cout << "Please input your electronic signature: ";;
cin >> signature[counter];
counter++;
} while (signature[counter-1] != "Exit");
Notice that I changed cin >> signature[i] to signature[counter] since that is the variable that you incremented. In addition, the check is for counter-1 because you care about the last element while counter is the index to the "new" element that is about to be entered.
Hopefully that helped. Feel free to ask for clarification.