I'm trying to get the program to loop back to the friends array and re-compare the two user inputs again and keep doing it until the 2nd input is the same as the first. We haven't covered this yet in my class but could someone help me to find this out? Since it is only and array[3] I only needed 2 of the index to match.

{		
			for(int num = 0; num < 3; num++)
			{
				cin >> input;
				mystery[num]= input;
			}

			for (int buddynum = 0; buddynum < 3; buddynum++)
			{
				cin >> newinput;
				friends[buddynum] = newinput;
			}

			if (mystery[0] == friends[0] || mystery[1] == friends[1])
				cout << "You guessed right!";
			else //This is where i need a call to the friend loop
		}

Recommended Answers

All 4 Replies

Put lines 10 thru 19 in another loop and break out of the loop if the user guessed right.

Ok, , this is what I came up with so far but I'm getting a syntax error (=) in the
first while loop when I try and compile this. I thought !== and == were to compare statements. Any suggestions?

{		
			for(int num = 0; num < 3; num++)
			{
				cin >> input;
				mystery[num]= input;
			}

		do
		{
			for (int buddynum = 0; buddynum < 3; buddynum++)
			{
				cin >> newinput;
				friends[buddynum] = newinput;
			}
		}
			while (mystery[0] !== friends[0] && mystery[1] !== friends[1]);

				do
				{
					cout << "You guessed right!";
				}
					while (mystery[0] == friends[0] && mystery [1] == friends[1]);
		}

you have too many = symbols -- its == and !=

the loop at lines 18-22 isn't going to work. Move line 20 to after line 13 then delete the rest of the loop at lines 18-22. Another way to code it is like this:

bool done = false;
while( done == false)
{
    for (int buddynum = 0; buddynum < 3; buddynum++)
    {
         cin >> newinput;
         friends[buddynum] = newinput;
    }
    if (mystery[0] == friends[0] || mystery[1] == friends[1])
    {
          cout << "You guessed right!";
          done = true;
    }

}

Thanks AD, for some reason a bool solution didn't come to my mind. Program runs good!

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.