| | |
Loop back to previous loop?
Please support our C++ advertiser: Intel Parallel Studio Home
Thread Solved |
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.
c++ Syntax (Toggle Plain Text)
{ 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 }
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.
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?
first while loop when I try and compile this. I thought !== and == were to compare statements. Any suggestions?
c++ Syntax (Toggle Plain Text)
{ 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]); }
Last edited by Ancient Dragon; Dec 16th, 2007 at 11:15 pm. Reason: add line numbers
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:
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:
C++ Syntax (Toggle Plain Text)
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; } }
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.
![]() |
Similar Threads
- VB/Access - Difference between two dates (Visual Basic 4 / 5 / 6)
- Send data on a serial port (C++)
- XP Startup Problem: Infinite Loop (Windows NT / 2000 / XP)
- number of times each number in array occurs? (C)
- I need help covert my source code frm pic16c54a to pic16f84a (Assembly)
- Reading in certain columns from CSV files into array C++ (C++)
- problem with MATLAB loop (Legacy and Other Languages)
- Clearing input (C)
- how many of you use 1.5? (Java)
Other Threads in the C++ Forum
- Previous Thread: Seperating and Sorting Strings
- Next Thread: programming C or C++ on my symbian phone S60 v3 (nokia e61i)
| Thread Tools | Search this Thread |
api array arrays based beginner binary bitmap c++ c/c++ calculator char char* class classes coding compile compiler console conversion convert count data database delete desktop developer directshow dll dynamiccharacterarray email encryption error file forms fstream function functions game generator getline google graph homeworkhelper iamthwee ifstream input int integer java lib linkedlist linux list loop looping loops map math matrix memory multiple news node number numbertoword output parameter pointer problem program programming project proxy python random read recursion recursive reference return rpg sorting string strings struct template templates text tree unix url vector video visualstudio win32 windows winsock word wordfrequency wxwidgets






