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
