Thread: Omg Last Time I Swear!

  1. #1
    Registered User
    Join Date
    Nov 2005
    Posts
    17

    Omg Last Time I Swear!

    OMG it was all going well, until right now I don't know why all of a sudden when I run the game, it tells me COngratulations you've won when I have won, and at the same time it says BETTER LUCK NEXT TIME?????? What is wrong with this code? I have no idea why it's doing this, someone please help me!

    Code:
    #include <iostream>
    #include <cstdlib>
    #include <fstream>
    #include <string>
    #include <cmath>
    
    using namespace std;
    
    void define_word(char d);
    
    
    int main()
    {   
    	char c, ch, ch1, ch2;
    	char word[50];
    	char word1[25];
    	int length, i, next_guess, num_letters, m, x;
    
    	do
    	{  
    		do
    		{
    		cout<<"\n\n\n\t* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *\n";
    		cout<<"\t******************* PrOgRaMmInG VoCaB GuEsSeR ********************\n";
    		cout<<"\t* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *\n\n\n";
    		cout<<"\n\t(S) Start the Game\n\n\t(Q) Quit\n\n\n\t Enter your choice: ";
    		
    		cin>> ch2;
    
    		}while	(ch2 != 's' && ch2 != 'S' && ch2 != 'Q' && ch2 != 'q');
    	
    	if	(ch2 == 'Q' || ch2=='q')  exit (0);
    
    	if	(ch2 == 's' || ch2=='S')
    
    	{
    		ifstream fin("words.txt");
    		if	(!fin)
    		{ 
    		cout<<"\n\nYou are missing a file called words.txt\n\n"; 
    		
    		return 0;
    		}
    		
    		for (i=0;!fin.eof();i++)   fin.getline(word,25);
    		fin.close();
    
    		do 
    		{
    		x=rand();
    		}while(x>i || x<0);
    
    		ifstream finn("words.txt");
    		
    		for (i=0;!finn.eof();i++)
    
    		{
    		finn>>c; finn.getline(word,25);
    		if (x==i) break;
    		}
    		finn.close();
    	}
    	
    	if	(ch2 == 'S' || ch2=='s')
    	{
    		length=strlen(word);		//Computes the length of the string
    		char choosen[50]="\0";
    		num_letters=0; 
    		m=0;
    
    	for	(i=0; i<=24; i++)
    	
    	{
    		if (word[i]=='\0') {word1[i]='\0'; break;}
    		if (word[i]==' ')  {word1[i]=' ';  num_letters++;}
    		if (word[i]!=' ')  word1[i]='-';
    	}
    
    	next_guess=length+2-num_letters;     //Number of Guesses Left
    	do
    	{
    		definition:  define_word(c);
    		if (m!=0)  cout<<"\n\n\t\t\tChoosen letters : "<<choosen<<"\n";
    		cout<<"\n\n\n\t\t\t      "<<word1;
    		cout<<"\n\n\n\tYou have "<<next_guess<< " guesses left, choose a letter : ";
    		cin>>ch; cin.get();
    		for (i=0;i<25;i++) 
    			
    		if (choosen[i]==ch) 
    		{
    		cout<<"You have choosen "<< ch <<" already!!\n"; goto definition;
    		}
    		
    		next_guess--; 
    		choosen [m]=ch; 
    		choosen [m+1]=',';
    		m+=2;
    
    		for (i=0;i<=49;i++)    
    			
    		if (word[i]==ch || word[i]==ch+32 || word[i]==ch-32) word1[i]=ch;
    		if (!strcmpi (word1,word))
    		{
    			cout<<"\n\t\t\t      "<<strupr(word);
    			cout<<"\n\n\t\t\tCongratulations, You have won!\n"; 
    			break;
    		}
    
    	}while(next_guess>0 || !strcmpi (word1,word));
    
    		if (strcmpi (word1,word))  
    		{
    		cout<<"\n\tBETTER LUCK NEXT TIME.\n\n\tTHE WORD IS : "<<strupr(word)<<endl;
    		}
    
    
    	cout<<"\n\tWould you like to play again? [Y or N] : ";
    	cin>>ch1;  cin.get();
    
    	}while (ch1=='y' || ch1=='Y');
    
    		system("PAUSE");
    		return 0;
    }
    please help me i appreciate it, this is the last time im posting

  2. #2
    Registered User
    Join Date
    Nov 2005
    Posts
    17
    Why is this happenning to me? Now i have this error, don't see reason why?
    fatal error C1071: unexpected end of file found in comment

  3. #3
    Registered User
    Join Date
    Jan 2005
    Posts
    7,366
    It looks like your braces and/or comments are not matching up. Fix your indentation and you may be able to see mismatched comment is.

  4. #4
    Shibby willc0de4food's Avatar
    Join Date
    Mar 2005
    Location
    MI
    Posts
    378
    WOWTHATSAMESS....
    lol thats just . bad.
    but i found your problem.
    Code:
    #include <iostream>
    #include <cstdlib>
    #include <fstream>
    #include <string>
    #include <cmath>
    
    using namespace std;
    
    void define_word(char d);
    
    
    int main()
    {   
    	char c, ch, ch1, ch2;
    	char word[50];
    	char word1[25];
    	int length, i, next_guess, num_letters, m, x;
    
    	do
    	{  
    		do
    		{
    		   cout<<"\n\n\n\t* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *\n";
    		   cout<<"\t******************* PrOgRaMmInG VoCaB GuEsSeR ********************\n";
    		   cout<<"\t* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *\n\n\n";
    		   cout<<"\n\t(S) Start the Game\n\n\t(Q) Quit\n\n\n\t Enter your choice: ";
    		
    		   cin>> ch2;
    
    		}while	(ch2 != 's' && ch2 != 'S' && ch2 != 'Q' && ch2 != 'q');
    	
    	    if	(ch2 == 'Q' || ch2=='q')  exit (0);
    
    	    if	(ch2 == 's' || ch2=='S')
    	    {
    		    ifstream fin("words.txt");
    		    if	(!fin)
    		    { 
    		        cout<<"\n\nYou are missing a file called words.txt\n\n"; 
    		
    		        return 0;
                        }
    		
    		    for (i=0;!fin.eof();i++)   fin.getline(word,25);
    		    fin.close();
    
    		    do 
    		    {
    		       x=rand();
                        }while(x>i || x<0);
    
    		    ifstream finn("words.txt");
    		
    		    for (i=0;!finn.eof();i++)
    		    {
    		        finn>>c; finn.getline(word,25);
    		        if (x==i) break;
                        }
    		    finn.close();
    	    }
    	
    	    if	(ch2 == 'S' || ch2=='s')
    	    {
    	     	length=strlen(word);		//Computes the length of the string
    		    char choosen[50]="\0";
    		    num_letters=0; 
    		    m=0;
    
    	        for	(i=0; i<=24; i++)
    		{
    		        if (word[i]=='\0') {word1[i]='\0'; break;}
    		        if (word[i]==' ')  {word1[i]=' ';  num_letters++;}
    		        if (word[i]!=' ')  word1[i]='-';
                    }
    
    	        next_guess=length+2-num_letters;     //Number of Guesses Left
    	        do
    	        {
    	        	definition:  define_word(c);
    		        if (m!=0)  cout<<"\n\n\t\t\tChoosen letters : "<<choosen<<"\n";
    		        cout<<"\n\n\n\t\t\t      "<<word1;
    		        cout<<"\n\n\n\tYou have "<<next_guess<< " guesses left, choose a letter : ";
    		        cin>>ch; cin.get();
    		        for (i=0;i<25;i++) 
    			
    		        if (choosen[i]==ch) 
    		        {
    		            cout<<"You have choosen "<< ch <<" already!!\n"; goto definition;
                             }
    		
    		        next_guess--; 
    		        choosen [m]=ch; 
    		        choosen [m+1]=',';
    		        m+=2;
    
    		        for (i=0;i<=49;i++)    
    			
    		        if (word[i]==ch || word[i]==ch+32 || word[i]==ch-32) word1[i]=ch;
    		        if (!strcmpi (word1,word))
    		        {
    		        	cout<<"\n\t\t\t      "<<strupr(word);
    			        cout<<"\n\n\t\t\tCongratulations, You have won!\n"; 
    			        break;
                            }
    
                        }while(next_guess>0 || !strcmpi (word1,word));
    
    		    if (strcmpi (word1,word))  
    		    {
    		        cout<<"\n\tBETTER LUCK NEXT TIME.\n\n\tTHE WORD IS : "<<strupr(word)<<endl;
                        }
    
    
    	        cout<<"\n\tWould you like to play again? [Y or N] : ";
    	        cin>>ch1;  cin.get();
    
        }while (ch1=='y' || ch1=='Y');
    
        system("PAUSE");
        return 0;
    }
    you never close off your if statement
    Last edited by willc0de4food; 12-13-2005 at 12:52 AM.
    Registered Linux User #380033. Be counted: http://counter.li.org

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Replies: 26
    Last Post: 07-05-2010, 10:43 AM
  2. Last Time with this Program ... I swear!
    By DonFord81 in forum C Programming
    Replies: 18
    Last Post: 03-16-2009, 01:10 PM
  3. Sending an email in C program
    By Moony in forum C Programming
    Replies: 28
    Last Post: 10-19-2006, 10:42 AM
  4. calculating user time and time elapsed
    By Neildadon in forum C++ Programming
    Replies: 0
    Last Post: 02-10-2003, 06:00 PM
  5. time class
    By Unregistered in forum C++ Programming
    Replies: 1
    Last Post: 12-11-2001, 10:12 PM