# Help! Looping problem.

Show 80 post(s) from this thread on one page
Page 1 of 2 12 Last
• 12-13-2012
Meerul264
Help! Looping problem.
Why can't I stop the loop even after I put

while ("answer" != 0);

on the answer input I press 0, but the loop still continue.

Code:

``` //User input poll of "Do you like _______ ?" //3 possible poll responds; r1, r2, r3. #include <iostream>; #include <string>; using namespace std; int main() {  //question     string poll;     //answers     string answer;     string y;     string n;         int count1;//yes     int count2;//no     int count3;//no idea     cout << "NOTE: There are only 3 possibles answers to this poll:\n";     cout << "1.yes.\n";     cout << "2.no. \n";     cout << "3.no idea \n";     cout << "Press the answer's number and then ENTER to add poll.\n";     cout << "Example: press 1 to answer yes.\n";     cout << "To end poll, press 0.\n";     cout << "What would you like to ask? (Type below) \n\n";     getline(cin, poll);         do     {                     cout << "Vote for yes? y/n \n";             cin >> answer;               if ( answer != "y" || answer != "n")               { cout << "Invalid choice.\n"; }                         }     while ( "answer" != 0);     system("pause");     return 0; }```
• 12-13-2012
Meerul264
ohh nevermind... I should make it (answer != "0") instead of ("answer" != 0)..

but Im new to this.. is the one in the quotation mark indicate that it is an input to be compared?
• 12-13-2012
Lesshardtofind
try
Code:

`while( answer != "0")`
While you are at it look at

Code:

`if ( "answer" != y || "answer" != n)`
And finally think about how they apply to each other.
• 12-13-2012
Meerul264
yeah I just realised that too... thanks.
• 12-13-2012
Meerul264
I also asked to make a poll. Can you please give me an idea?
• 12-13-2012
Lesshardtofind
You could start by getting the input for the poll and then compare the input to a constant and finally increase the correct variable.
Further you could add an error check or a while loop to ensure you get an answer that you want.
• 12-13-2012
Meerul264
Haven't made the poll yet. But Is this the correct way to obtain input for the polls?

Code:

``` //User input poll of "Do you like _______ ?" //3 possible poll responds; r1, r2, r3. #include <iostream>; #include <string>; using namespace std; int main() {  //question         string poll;         //answers         string answer;         string answer2;         string answer3;         string y;         string n;                         int count1;//yes         int count2;//no         int count3;//no idea     cout << "NOTE: There are only 3 possibles answers to this poll:\n";         cout << "1.yes.\n";         cout << "2.no. \n";         cout << "3.no idea \n";         cout << "Press the answer's number and then ENTER to add poll.\n";         cout << "Example: press 1 to answer yes.\n";         cout << "To end poll, press 0.\n";         cout << "What would you like to ask? (Type below) \n\n";         getline(cin, poll);                 do         {                                     cout << "Vote for yes? y/n \n";                         cin >> answer;                         cout << "Vote for no? y/n \n";                         cin >> answer2;                         cout << "Voute for no idea? y/n \n";                         cin >> answer3;                                                                                                                                         if ( answer != "y" && answer != "n" || answer2 != "y" && answer2 != "n" || answer3 != "y" && answer3 != "n")                           { cout << "Invalid choice.\n"; }                                                                                                 }         while ( answer != "0");                                   system("pause");         return 0; }```
• 12-13-2012
Lesshardtofind
You are going to want to add () around the compound comparisons.
Code:

` if ((answer != "y" && answer != "n") || (answer2 != "y" && answer2 != "n") || (answer3 != "y" && answer3 != "n"))`
are you compiling this as you go? Your compiler should be giving you errors for these, or at least warnings. It would be alot more useful for you if you posted your compiler errors with your code and I helped you understand what they mean.
• 12-13-2012
Meerul264
I'm not really what you mean by "compiling this as I go". But all I know is that I'm using a debugger in Microsoft Visual C++ Express.

All I ever do since I start learning this a week ago, is learning the language, and then debug (pressing F5), to see the output.

I don't think I receive any errors, though.

Anyway, here's what comes out after I debug it:

'User input poll.exe': Loaded 'C:\Users\user\Documents\Visual Studio 2010\Projects\User input poll\Debug\User input poll.exe', Symbols loaded.
'User input poll.exe': Loaded 'C:\Windows\SysWOW64\ntdll.dll', Cannot find or open the PDB file
'User input poll.exe': Loaded 'C:\Windows\SysWOW64\kernel32.dll', Cannot find or open the PDB file
'User input poll.exe': Loaded 'C:\Windows\SysWOW64\KernelBase.dll', Cannot find or open the PDB file
'User input poll.exe': Loaded 'C:\Windows\SysWOW64\msvcp100d.dll', Symbols loaded.
'User input poll.exe': Loaded 'C:\Windows\SysWOW64\msvcr100d.dll', Symbols loaded.
• 12-13-2012
Lesshardtofind
Yea debugging is equivalent. So if it is running what is the holdup now?

http://www.kirupa.com/forum/showthre...first-practise

addresses the Cannot find or Open the PDB file
• 12-13-2012
Meerul264
Quote:

You could start by getting the input for the poll
I've done this part, right?

Quote:

and then compare the input to a constant

Quote:

and finally increase the correct variable.
I can use for loops, do while loops and while loops for this, right?
Correct me if I'm wrong please.
• 12-13-2012
Elysia
Quote:

Originally Posted by Meerul264
ohh nevermind... I should make it (answer != "0") instead of ("answer" != 0)..

but Im new to this.. is the one in the quotation mark indicate that it is an input to be compared?

Anything in string literal ("hello world") is a string (C string to be precise). Thus, in the second one, you compare a string literal to an integer. This doesn't make, but unfortunately works due to the nature of C style strings (I hope we get "real" C++ string literals in the future).
The first compares the variable answer to the string literal "0", which is what you want.
That is why it works, and not the first.

Also, since you seem to be new to loops, you should not ask people "how do I do this?". There are a thousand variants, and you cannot learn them all.
Ever heard of flowcharts? Try making one for what you want, then translating that into code. Flowcharts help you build your logic and loops.

As for the output you see in the output window, it's normal and nothing you have to worry about.
Essentially, a pdb file is a file that contains debugging information. Any executable you make have dependencies on some Windows components, and by default, these files have no debugging information associated with them. That's why you get "cannot find or open pdb file."
But since you are not going to debug those files, you don't need that information, so you can ignore it. The important thing is that it loads the pdb (debugging info) from your own executable, which it is in this case.
• 12-13-2012
Meerul264
Hmm should I make a flowchart that follows my book? Like one flowchart for each chapter?

And by "you cannot learn them all", did you meant it by "I cannot learn them all at once", or that "I shouldn't learn them all, because only the important things are needed"?
• 12-13-2012
Elysia
There are an infinity number of different combinations of loops. You cannot learn them all.
You should make a flowchart if you cannot mentally picture how to make a loop required for the task you are doing.
• 12-13-2012
Meerul264
I'm using flowchart and I think I can depict the code now. Thanks... I'll try to post the code here, I hope you can help later with it if I have any problem.
Show 80 post(s) from this thread on one page
Page 1 of 2 12 Last