### Help

I am attempting to create a guessing number game. However, it only shows if the number is too high, not if it's correct or too low. Help would be appreciated!

And please, do not criticize any of my methods of coding, I am fairly new to this.
:)

First .cpp:
-----------------------------------------------------------
#include "stdafx.h"
#include <iostream>
#include <ctime>
#include <cstdlib>

int y;

int tHigh();
int tLow();
int correct();

int getRandom()
{

srand(time(0));
return rand();

}

int ret() //Return Value 0
{
return 0;
}

int ret1() //Return Value 1
{
return 1;
}

int Try(int c) //Try #
{
using namespace std;
int x;
cin >> x;
//If Functions:
if (x>c)

y = tHigh();
return y; // Too ^

if (x<c)

y = tLow();
return y; // Too v

if (x=c)

y = correct(); // Just Right
return y;

}
//Results:
int tHigh()
{
using namespace std;
cout << "Too High!" << endl;
int rValue = ret();
return rValue;

}

int tLow()
{
using namespace std;
cout << "Too Low!" << endl;
int rValue = ret();
return rValue;
}

int correct()
{
using namespace std;
cout << "Correct!" << endl;
int rValue = ret1();
return rValue;
}
----------------------------------------------------------

Second .cpp:
----------------------------------------------------------
#include "stdafx.h"
#include <iostream>

int getRandom();
int Try(int c);
long gr = getRandom();

int main()
{

using namespace std;
cout << "Guess a Number!" << endl;
int n = 0;
while(n==0)
n = Try(gr);
return 0;

}
--------------------------------------------
 ``12345`` ``````//If Functions: if (x>c) y = tHigh(); return y; // Too ^ ``````

What is happening
 ``1234567`` ``````//If Functions: if (x>c) { y = tHigh(); } return y; // Too ^ ``````

What you want
 ``1234567`` ``````//If Functions: if (x>c) { y = tHigh(); return y; // Too ^ }``````
Exactly what he said! ^
Use curly brackets for if statements unless if there is only 1 line of code you need to execute if the if statement is true.
Topic archived. No new replies allowed.