Loop back to previous loop?

Please support our C++ advertiser: Intel Parallel Studio Home
Thread Solved

Join Date: Dec 2007
Posts: 6
Reputation: stokey is an unknown quantity at this point 
Solved Threads: 0
stokey's Avatar
stokey stokey is offline Offline
Newbie Poster

Loop back to previous loop?

 
0
  #1
Dec 16th, 2007
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.


  1.  
  2.  
  3. {
  4. for(int num = 0; num < 3; num++)
  5. {
  6. cin >> input;
  7. mystery[num]= input;
  8. }
  9.  
  10. for (int buddynum = 0; buddynum < 3; buddynum++)
  11. {
  12. cin >> newinput;
  13. friends[buddynum] = newinput;
  14. }
  15.  
  16. if (mystery[0] == friends[0] || mystery[1] == friends[1])
  17. cout << "You guessed right!";
  18. else //This is where i need a call to the friend loop
  19. }
Last edited by Ancient Dragon; Dec 16th, 2007 at 10:28 pm. Reason: add line numbers -- this is NOT a violation of any rule but doing this for discussion convenience.
Reply With Quote Quick reply to this message  
Join Date: Aug 2005
Posts: 15,433
Reputation: Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute 
Solved Threads: 1471
Team Colleague
Featured Poster
Ancient Dragon's Avatar
Ancient Dragon Ancient Dragon is offline Offline
Still Learning

Re: Loop back to previous loop?

 
0
  #2
Dec 16th, 2007
Put lines 10 thru 19 in another loop and break out of the loop if the user guessed right.
Don't PM me with questions -- you might get a nasty PM in response. If you have a question then post it in one of the forums.
Reply With Quote Quick reply to this message  
Join Date: Dec 2007
Posts: 6
Reputation: stokey is an unknown quantity at this point 
Solved Threads: 0
stokey's Avatar
stokey stokey is offline Offline
Newbie Poster

Re: Loop back to previous loop?

 
0
  #3
Dec 16th, 2007
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?

  1. {
  2. for(int num = 0; num < 3; num++)
  3. {
  4. cin >> input;
  5. mystery[num]= input;
  6. }
  7.  
  8. do
  9. {
  10. for (int buddynum = 0; buddynum < 3; buddynum++)
  11. {
  12. cin >> newinput;
  13. friends[buddynum] = newinput;
  14. }
  15. }
  16. while (mystery[0] !== friends[0] && mystery[1] !== friends[1]);
  17.  
  18. do
  19. {
  20. cout << "You guessed right!";
  21. }
  22. while (mystery[0] == friends[0] && mystery [1] == friends[1]);
  23. }
Last edited by Ancient Dragon; Dec 16th, 2007 at 11:15 pm. Reason: add line numbers
Reply With Quote Quick reply to this message  
Join Date: Aug 2005
Posts: 15,433
Reputation: Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute 
Solved Threads: 1471
Team Colleague
Featured Poster
Ancient Dragon's Avatar
Ancient Dragon Ancient Dragon is offline Offline
Still Learning

Re: Loop back to previous loop?

 
0
  #4
Dec 16th, 2007
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:
  1. bool done = false;
  2. while( done == false)
  3. {
  4. for (int buddynum = 0; buddynum < 3; buddynum++)
  5. {
  6. cin >> newinput;
  7. friends[buddynum] = newinput;
  8. }
  9. if (mystery[0] == friends[0] || mystery[1] == friends[1])
  10. {
  11. cout << "You guessed right!";
  12. done = true;
  13. }
  14.  
  15. }
Last edited by Ancient Dragon; Dec 16th, 2007 at 11:19 pm.
Don't PM me with questions -- you might get a nasty PM in response. If you have a question then post it in one of the forums.
Reply With Quote Quick reply to this message  
Join Date: Dec 2007
Posts: 6
Reputation: stokey is an unknown quantity at this point 
Solved Threads: 0
stokey's Avatar
stokey stokey is offline Offline
Newbie Poster

Re: Loop back to previous loop?

 
0
  #5
Dec 16th, 2007
Thanks AD, for some reason a bool solution didn't come to my mind. Program runs good!
Reply With Quote Quick reply to this message  
Reply

This thread has been marked solved.
Perhaps start a new thread instead?
Message:


Thread Tools Search this Thread



About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC