G'day everyone!
I'm fairly new to C++, so bear with me if this is painfully obvious.
I'm trying to get a user to guess a string, which is just a vector containing random capital letters. That random letters part works great, however I can't figure out how to get my program to actually compare user input to the generated string in question. I decided to try a very simple program that would do only this and customize it to fit my main program, but I hit a bit of a bump. I need my program to print out that the user has guessed "x" amount of letters correctly (which I realize doesn't actually feature in this code, but that's because I just couldn't figure out how to do that)
#include <iostream>
#include <string>
#include <sstream>
int main(){
std::string name,name2;
int finish = 1;
std::cout << "name?\n";
std::cin >> name;
std::cout << "enter name 2\n";
while(finish != 0){
std::cin >> name2;
for (int i = 0; i != name.length())
{
if (name2[i] == name[i])
{
std::cout << "Correct!\n";
finish = 0;
}
else{
std::cout << "wrong\n";
}
}
std::cout << "name is " << name;
}
return 0;
}
The particular code is something I just quickly put together in order to test it a bit before putting it into my main program, so it looks a bit messy and shabby. My problem is that this will print out "Correct!" a name.length() amount of times, which I don't want, but I do need it to actually display something like "Correct, X letters right" only once per guess.
My thinking is that the program checks each letter in name2 to that same corresponding letter position in the original name1 , and store (somewhere) that a letter has been guessed correctly, but after hours of Google-Foo, I just can't figure this one out.
EDIT: To clarify, I mean that my code will return "correct" the x amount of times for every correct string, and only then will it print out a "wrong".
Any help would be greatly appreciated!