RSS Forums RSS
Please support our C++ advertiser: Programming Forums
Views: 1018 | Replies: 2 | Thread Tools  Display Modes
Reply
Join Date: Dec 2004
Posts: 471
Reputation: Acidburn is an unknown quantity at this point 
Rep Power: 5
Solved Threads: 5
Acidburn Acidburn is offline Offline
Posting Pro in Training

a class problem

  #1  
Sep 8th, 2005
Hey guys its me again!

I'm stuck on a logic thing of where to put some code. Basically I want to take an input from the keyboard and store that into an array using a class whilst combining it with the other stuff that the class does.

void hangman::getletter(char letter)
{ 
	int i;
   for ( i= 0 ;i < 4 ; i++)
   {
	  
      if( letter ==name[i] )
      {
       encryption[i] = name[i];
       break;	  
      }     
   }

   if (i == 4)
      {
         cout << "not found" <<endl;
         looselife();
	    

      }
   
}


I though of adding it onto the end of here but not sure what the code would be. I've made a buffer to store it in and set it using the constructor, but how would i go about moving the 'i' (counter) everytime this function is called to aviod over writing of the array?

John........
AddThis Social Bookmark Button
Reply With Quote  
Join Date: Jun 2005
Posts: 33
Reputation: shre86 is an unknown quantity at this point 
Rep Power: 4
Solved Threads: 1
shre86 shre86 is offline Offline
Light Poster

Re: a class problem

  #2  
Sep 10th, 2005
Why dont u return the value of i to ur parent function and then whenever u have to perform the operation pass i as a parameter to it??
Reply With Quote  
Join Date: Jul 2005
Posts: 244
Reputation: Drowzee is an unknown quantity at this point 
Rep Power: 4
Solved Threads: 4
Drowzee Drowzee is offline Offline
Posting Whiz in Training

Re: a class problem

  #3  
Sep 12th, 2005
As shre86 said, if you want to keep the scope of the counter, it might behoove you to pass (and possibly return) i as a parameter.

But really, what do you want this function to do? If the user enters a correct letter, what happens in your overall program? What happens if the user guesses incorrectly? There may be a better way to solve your problem, but we'll need more information before a really useful answer can be given.
Reply With Quote  
Reply

Only community members can participate in forum threads. You must register or log in to contribute.



Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)

 

Thread Tools Display Modes
Forums | Blogs | Tutorials | Code Snippets | Whitepapers | RSS Feeds | Advertising
All times are GMT -4. The time now is 3:59 am.
Newsletter Archive - Sitemap - Privacy Statement - Acceptable Use Policy - Contact Us
Forum system based on vBulletin Copyright ©2000 - 2009, Jelsoft Enterprises Ltd.
©2003 - 2008 DaniWeb® LLC