C++ For Loop User Response

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

Join Date: Jul 2006
Posts: 7
Reputation: Simon268 is an unknown quantity at this point 
Solved Threads: 0
Simon268 Simon268 is offline Offline
Newbie Poster

C++ For Loop User Response

 
0
  #1
Jul 20th, 2006
Hi all.

I can't get this to compile;

  1.  
  2.  
  3. #include <iostream>
  4. #include <string>
  5. using namespace std;
  6.  
  7. int main ()
  8.  
  9. {
  10.  
  11. int number;
  12. string response;
  13.  
  14. for (number=5; response!='Y';)
  15. {
  16. cout <<number <<endl;
  17. cout <<"Had Enough (Y/N)?";
  18. cin>>response;
  19. }
  20.  
  21. cin.get ();
  22. cin.get ();
  23.  
  24. return 0;
  25.  
  26. }

when i try to compile this message comes up:

  1.  
  2. no match for 'operator!=' in 'response!='Y''

What does this mean? What can i do to get it to work?

Any help would be greately appreciated.
Reply With Quote Quick reply to this message  
Join Date: Jun 2005
Posts: 1,496
Reputation: WolfPack has a spectacular aura about WolfPack has a spectacular aura about WolfPack has a spectacular aura about 
Solved Threads: 104
Moderator
WolfPack's Avatar
WolfPack WolfPack is offline Offline
Mentally Challenged Mod.

Re: C++ For Loop User Response

 
0
  #2
Jul 20th, 2006
try
  1. char response = 'N';
.
バルサミコ酢やっぱいらへんで
Reply With Quote Quick reply to this message  
Join Date: Jul 2006
Posts: 7
Reputation: Simon268 is an unknown quantity at this point 
Solved Threads: 0
Simon268 Simon268 is offline Offline
Newbie Poster

Re: C++ For Loop User Response

 
0
  #3
Jul 20th, 2006
Thanks

This does get it to compile.

Though whether i type N,n or Y,y it just continues to loop the question, never terminating.
Reply With Quote Quick reply to this message  
Join Date: Jul 2006
Posts: 147
Reputation: Grunt has a spectacular aura about Grunt has a spectacular aura about 
Solved Threads: 12
Grunt's Avatar
Grunt Grunt is offline Offline
Junior Poster

Re: C++ For Loop User Response

 
0
  #4
Jul 20th, 2006
Originally Posted by WolfPack
try
  1. char response = 'N';
.
Or
response !="Y"
Reply With Quote Quick reply to this message  
Join Date: Jul 2006
Posts: 7
Reputation: Simon268 is an unknown quantity at this point 
Solved Threads: 0
Simon268 Simon268 is offline Offline
Newbie Poster

Re: C++ For Loop User Response

 
0
  #5
Jul 20th, 2006
Originally Posted by Grunt
Or
response !="Y"
When i do that it wont compile saying;

  1. expected primary-expression before "char"
Reply With Quote Quick reply to this message  
Join Date: Jul 2006
Posts: 26
Reputation: portege is an unknown quantity at this point 
Solved Threads: 1
portege portege is offline Offline
Light Poster

Re: C++ For Loop User Response

 
0
  #6
Jul 20th, 2006
char response;

for (number=5; response!='Y' and response != 'y'
Reply With Quote Quick reply to this message  
Join Date: Jul 2006
Posts: 7
Reputation: Simon268 is an unknown quantity at this point 
Solved Threads: 0
Simon268 Simon268 is offline Offline
Newbie Poster

Re: C++ For Loop User Response

 
0
  #7
Jul 20th, 2006
Originally Posted by portege
char response;

for (number=5; response!='Y' and response != 'y'
Cheers - got it to work!!! - though response !='y' seemed to be redunant.

Now i'm playing around to figure out how to make it repeat the question if you just type return - though i have a fealing it is far to complex for me right now!
Last edited by Simon268; Jul 20th, 2006 at 11:51 am.
Reply With Quote Quick reply to this message  
Reply

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



Similar Threads
Other Threads in the C++ Forum
Thread Tools Search this Thread



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

©2003 - 2009 DaniWeb® LLC