In C++ the listed headers
1 2 3
|
#include <time.h>
#include <stdio.h>
#include <stdlib.h>
|
should be written as
1 2 3
|
#include <ctime>
#include <cstdio>
#include <cstdlib>
|
And I do not understand why was stdio.h included?!
I do not see any sense to define a variable of type std::string to store file name
string befajlnev = "words.txt"; // creating a file
I think it would be better to define it as
const char *befajlnev = "words.txt";
Also by default ifstream objects have open mode ios::in. So it would be simply to write
ifstream befajl( befajlnev ); // for reading
instead of
ifstream befajl(befajlnev.c_str(), ios::in); // for reading
Also I do not see any sense to define variable random_max.
Instead of the loop while as below
1 2 3 4 5 6 7 8 9 10 11
|
while(vege != true) // main loop...
{
cout << "Guess it: ";
cin >> probalkozas;
if( probalkozas == szo )
{
vege = true;
cout << "You guessed it right in " << guesses << " guesses.\n";
}
guesses++;
}
|
it would be better to use the loop do-while
1 2 3 4 5 6 7 8 9 10 11
|
do // main loop...
{
cout << "Guess it: ";
cin >> probalkozas;
if( probalkozas == szo )
{
vege = true;
cout << "You guessed it right in " << guesses << " guesses.\n";
}
guesses++;
} while ( ! vege );
|
This loop shall be rewritten in whole the following way
1 2 3 4 5 6 7 8 9 10
|
do // main loop...
{
cout << "Guess it: ";
cin >> probalkozas;
guesses++;
vege = probalkozas == szo;
} while ( ! vege );
cout << "You guessed it right in " << guesses << " guesses.\n";
|
So in general your code is bad.
Also the initial value of guesses shall be 0.
And it is a bad programming style when your variables have non-english names. It is difficult to read such programs.