Welcome
Welcome to the forums of AntiRTFM's Absolute N00b Spoonfeed C++ Tutorials!

You are currently viewing our boards as a guest, which gives you limited access to view most discussions and access our other features. By joining our free community, you will have access to post topics, communicate privately with other members (PM), respond to polls, upload content, and access many other special features. Registration is fast, simple, and absolutely free, so please, <a href="/profile.php?mode=register">join our community today</a>!

i cant get it to cout you win

Ask ALL your questions here

i cant get it to cout you win

Postby masterkey on Tue Oct 13, 2009 11:57 am

Code: Select all
#include<iostream>
#include<string>
#include<windows.h>

using namespace std;

int main()
{
   char letter = NULL;
bool ab = false;
bool cd = false;
bool ef = false;
bool gh = false;
bool ij = false;
bool kl = false;
bool mn = false;
   cout <<"lets play hangman\n\n";
      Sleep(1000);
      
      cout <<"guess what this word is..  _ _ _ _ _ _\n";
      do{
         
            
               
                  
                     
                        
      cin>>letter;
   
      
switch(letter)
{
case'a':

   cout<<"there is no _a_ in this word\n";
   break;
case'c':
   
      cout<<"there is no _c_ in this word\n";
   break;
case'd':
   
      cout<<"there is no _d_ in this word\n";
   break;
case'e':
   
      cout<<"congratulation there is an e \n";
      kl = true;
   break;

case'f':
   
      cout<<"there is no _f_ in this word\n";

   break;
case'g':
   
      cout<<"there is no _g_ in this word\n";
   break;
case'h':
   
      cout<<"there is no _h_ in this word\n";
   break;
case'i':
   
      cout<<"there is no _i_ in this word\n";
   break;
case'j':
   
      cout<<"there is no _j_ in this word\n";
   break;
case'l':
   
      cout<<"there is no _l_ in this word\n";
   break;

case'm':
   
      cout<<"\ncongratulation there is an m\n";
ab =true;
break;
case'n':
   
      cout<<"congratulation there is an n\n";
   ef=true;
   break;

case'o':
   cd = true;
      cout<<"congratulation there is an o\n";
 
      break;
case'p':
   
      cout<<"there is no _p_ in this word\n";
   break;
case'q':
   
      cout<<"there is no _q_ in this word\n";
   break;
case'r':
   
      cout<<"congratulation there is an r\n";
mn =true;
   break;
   
case's':
   gh = true;
      cout<<"congratulation there is an s\n";
      
   break;

case't':
   
      cout<<"congratulation there is an t\n";
ij= true;
   break;
case'u':
   
      cout<<"there is no _u_ in this word\n";

   break;
case'v':
   
      cout<<"there is no _v_ in this word\n";
   break;

case'w':
   
      cout<<"there is no _w_ in this word\n";

   break;
case'x':
   
      cout<<"there is no _x_ in this word\n";

   break;
case'y':
   
      cout<<"there is no _y_ in this word\n";
   break;

case'z':
   
      cout<<"there is no _z_ in this word\n";
break;
}

}

while( cd != true || ab != true || ef != true || gh != true || ij != true || kl != true || mn != true);
cout<<"you win";

system("pause");
   
   return 0 ;
}



Last edited by masterkey on Tue Oct 13, 2009 1:04 pm, edited 3 times in total.
masterkey
 
Posts: 19
Joined: Tue Sep 22, 2009 5:31 pm

Re: i cant get it to cout you win

Postby Moosader on Tue Oct 13, 2009 12:02 pm

1. Pastebin, or the code tag.
2. Tell us what problems you're having.
3. Tell us what you've tried to fix it.
4. Why are there so many curly braces??? This might have something to do with the lack of Couting. The cout statements are fine, it's probably just not getting to that portion of code to execute.
5. Sleep(1000) is going to make it delay for a LONG TIME. I think just 1 makes it pause for one second.
User avatar
Moosader
 
Posts: 25
Joined: Mon Jul 06, 2009 5:31 pm
Location: Kansas City

Re: i cant get it to cout you win

Postby masterkey on Tue Oct 13, 2009 12:13 pm

this is a simple hang man game
that is supposed to tell you you_ win
once you type in the word monster
the only thing wrong is it is not reaching the line
cout<<"you win";
i dint know how to put all the boolean variables
in as 1 while parameter
masterkey
 
Posts: 19
Joined: Tue Sep 22, 2009 5:31 pm

Re: i cant get it to cout you win

Postby masterkey on Tue Oct 13, 2009 12:15 pm

thats why there is so many braces iwas getting compiler error until i put them in
masterkey
 
Posts: 19
Joined: Tue Sep 22, 2009 5:31 pm

Re: i cant get it to cout you win

Postby noobgrammer on Tue Oct 13, 2009 1:01 pm

Ok here you go with it working

Code: Select all
#include<iostream>
#include<string>
#include<windows.h>

using namespace std;

int main()
{
   char letter = NULL;
   bool ab = false;
   bool cd = false;
   bool ef = false;
   bool gh = false;
   bool ij = false;
   bool kl = false;
   bool mn = false;
   cout <<"lets play hangman\n\n";
   Sleep(1000);

   cout <<"guess what this word is.. _ _ _ _ _ _\n";
   do{

      cin>>letter;


      switch(letter)
      {
         case'a':
            
         cout<<"there is no _a_ in this word\n";
         break;
         
         case'c':
            
         cout<<"there is no _c_ in this word\n";
         break;
         
         case'd':
            
         cout<<"there is no _d_ in this word\n";
         break;
         
         case'e':
            
         cout<<"congratulation there is an e \n";
         kl = true;
         break;

         case'f':
            
         cout<<"there is no _f_ in this word\n";

         break;
         
         case'g':
            
         cout<<"there is no _g_ in this word\n";
         break;
         
         case'h':
            
         cout<<"there is no _h_ in this word\n";
         break;
         
         case'i':
            
         cout<<"there is no _i_ in this word\n";
         break;
         
         case'j':
            
         cout<<"there is no _j_ in this word\n";
         break;
         
         case'l':
            
         cout<<"there is no _l_ in this word\n";
         break;

         case'm':
            
         cout<<"\ncongratulation there is an m\n";
         ab =true;
         break;
            
         case'n':
            
         cout<<"congratulation there is an n\n";
         ef=true;
         break;
         
         case'o':
            
         cout<<"congratulation there is an o\n";
         cd = true;
         break;
         
         case'p':
            
         cout<<"there is no _p_ in this word\n";
         break;
         
         case'q':
            
         cout<<"there is no _q_ in this word\n";
         break;
         
         case'r':
            
         cout<<"congratulation there is an r\n";
         mn =true;
         break;
         
         case's':
            
         cout<<"congratulation there is an s\n";
         gh = true;
         break;

         case't':
            
         cout<<"congratulation there is an t\n";
         ij= true;
         break;
         
         case'u':
            
         cout<<"there is no _u_ in this word\n";

         break;
         
         case'v':
            
         cout<<"there is no _v_ in this word\n";
         break;
            
         case'w':
            
         cout<<"there is no _w_ in this word\n";

         break;
         
         case'x':
            
         cout<<"there is no _x_ in this word\n";

         break;
         
         case'y':
            
         cout<<"there is no _y_ in this word\n";
         break;
            
         case'z':
            
         cout<<"there is no _z_ in this word\n";
            
   }

   }while( cd != true || ab != true || ef != true || gh != true || ij != true || kl != true || mn != true);
      

   cout<<"you win";
   //system("pause");

   return 0 ;
}


you where not using the do...while quite right its one do to one while so the others where just whiles.

you could probably get away without putting the whole alphabet down and only have the one's necessary by putting the (letter) inside a cout saying that is not it and only checking for the right one
I need a compiler with a can of RAID built into it

I added a msn messenger just for programming feel free to email or add yourself to it
User avatar
noobgrammer
 
Posts: 198
Joined: Tue Aug 25, 2009 10:44 am
Location: Orlando

Re: i cant get it to cout you win

Postby masterkey on Tue Oct 13, 2009 1:03 pm

cheer snoobgrammer
masterkey
 
Posts: 19
Joined: Tue Sep 22, 2009 5:31 pm


Return to QA

Who is online

Users browsing this forum: No registered users and 0 guests

cron