Continuous loop or counter problem or both?
I have coded a "guess the number" program. When the user inputs his guess, the program is supposed to tell him: "Excellent! Would you like to play again (y or n)?" or "Too Low. Try again." or "Too High. Try again.". The user is supposed to have 6 guesses before the game ends. My problem is that the program gives him one chance to enter a guess and then gives outputs all of the choices . I am not sure how to fix my program or where the error(s) are within the program.
Code:
#include <iostream>
using std::cout;
using std::cin;
using std::endl;
#include <cstdio>
#include <cstdlib>
#include <ctime>
int randomNumber();
void test(int yourGuess, int rnum);
void intro();
void main(void)
{
int i=0;
int rnum=0;
int yourGuess = 0;
int count = 0;
long ltime = time(NULL);
unsigned stime = (unsigned)(ltime/2);
intro();
cin >> yourGuess;
srand( time( 0 ));
for (i=0; i<6; i++)
{
rnum=randomNumber();
test( yourGuess, rnum);
}
return;
}
void intro(void)
{
cout << "I have a number between 1 and 1000.\n";
cout << "Can you guess my number?\n";
cout << "Please type your first guess.\n";
}
int randomNumber()
{
int number =-99999;
number= 1 + rand() % 1000;
return number;
}
void test(int yourGuess, int rnum)
{
if ( yourGuess < rnum )
cout << "Too Low. Try again" << endl;
else if ( yourGuess > rnum )
cout << "Too High. Try again" << endl;
if ( yourGuess = rnum )
cout << "EXCELLENT! You guessed the number!\n";
cout << "Would you like to play again (y or n)?" << endl;
}
I would appreciate it if someone could please point me to where in my program that my error(s) are so that I can try to fix them. Sorry to post the whole code but since I am not sure where the problem is I thought it might be needed.