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>!

Improved Guessing Game

Think you can spy out that little nasty bug? Try debugging some code in here

Improved Guessing Game

Postby Aert on Sun Aug 23, 2009 1:20 am

After watching the guessing game tutorial video, #16 or something, I've been adding onto it while i watch more and more videos. Im only on 19 atm, but this is what I have.
The guessing game has 3 tries for you to guess the number, (its always 2 because idk how to make it random) and i probably did way more than i needed, but i have no idea what im doing :)

Code: Select all
#include "stdafx.h"



#include <iostream>

using namespace std;

void 1tryleft()
{
   cout << "1 try left, guess again: ";
   cin >> playersGuess;

         if ( playersGuess == theNumber )
         {
            cout << "Congratulations! Your guess was correct. \n";
         }      
         else
         {
            if ( playersGuess < theNumber )
            {
               cout << "Too low! \n";
            }
            else
            {
               if (playersGuess > theNumber)
               {
                  cout << "Too high! \n";
               }
               else
               {
                  cout << "Unable to recognize. \n";
               }
            }
         }
}

void 2triesleft()
{


   cout << "2 tries left, guess again: ";
   cin >> playersGuess;

         if ( playersGuess == theNumber )
         {
            cout << "Congratulations! Your guess was correct. \n";
         }      
         else
         {
            if ( playersGuess < theNumber )
            {
               cout << "Too low! \n";
               1tryleft();
            }
            else
            {
               if (playersGuess > theNumber)
               {
                  cout << "Too high! \n";
                  1tryleft();
               }
               else
               {
                  cout << "Unable to recognize. \n";
               }
               else
               {
                  1tryleft();
               }
            }
         }
}

int main()
{
   int theNumber = 2;

   int playersGuess;

   cout << "Guess the number. \n";
   cout << "Type in a number from 1 - 10: ";
   cout << "you have 3 tries to guess the number. \n";

   cin >> playersGuess;
   bool alive = true;

         if ( playersGuess == theNumber )
         {
            cout << "Congratulations! Your guess was correct. \n";
         }      
         else
         {
            if ( playersGuess < theNumber )
            {
               cout << "Too low! \n";
               2triesleft();
            }
            else
            {
               if (playersGuess > theNumber)
               {
                  cout << "Too high! \n";
                  2triesleft();
               }
               else
               {
                  cout << "Unable to Recognize. \n";
               }
               else
               {
                  2triesleft();
               }
            }
         }

   cout << "The game has ended, type in anything and press enter to exit.";
   
   
   char f;
   cin >> f;
   return 0;
}

It has tons of errors that i cant figure out. I've looked at every line and it makes no sense that there would be an error.
IE: error C2146: syntax error : missing ';' before identifier 'triesleft'
Doesn't make sense that it would tell me to put a semicolon in front of triesleft

Im using Microsoft Visual C++ express edition 2008 for my compiler
Aert
 
Posts: 2
Joined: Sun Aug 23, 2009 12:58 am

Re: Improved Guessing Game

Postby antiRTFM on Sun Aug 23, 2009 11:57 pm

Variable, class, and function names cannot begin with a number
User avatar
antiRTFM
Administrator
 
Posts: 470
Joined: Sun Apr 13, 2008 9:10 am

Re: Improved Guessing Game

Postby Aert on Mon Aug 24, 2009 10:54 am

Thanks! i got to work now.
Aert
 
Posts: 2
Joined: Sun Aug 23, 2009 12:58 am


Return to Debug

Who is online

Users browsing this forum: No registered users and 0 guests