Hello iceman870,
PLEASE ALWAYS USE CODE TAGS (the <> formatting button) when posting code.
It makes it easier to read your code and also easier to respond to your post.
http://www.cplusplus.com/articles/jEywvCM9/
http://www.cplusplus.com/articles/z13hAqkS/
Hint: You can edit your post, highlight your code and press the <> formatting button.
You can use the preview button at the bottom to see how it looks.
In addition to what Repeater said about you for loopI see soe other problems.
#define _CRT_SECURE_NO_WARNINGS
If you have to use this you are doing something very wrong. Like maybe putting a C program in a .cpp file and compiling it as a C++ program.
int main(void)
Is n old C style way of writing this line and is no longer used in modern code. It may at the least give you a warning if not an error at compile time.
The lines
1 2
|
int r = rand() % 2;
srand(time(0));
|
Are backwards. And this
srand(time(0));
would be better written as
srand(unsigned int (time(0)));
"srand" only needs to be set once at the beginning of the program before "rand" is used.
The
scanf("%d", &guess);
is causing the need for
#define _CRT_SECURE_NO_WARNINGS
With my compiler the error message tells me to use
scanf_s
because it is more secure.
Your for loop deals with one entry for "guess" and does it 10 times because "guess" never changes. At the end of the for loop you need to input a new guess. A do/while or while loop is usually a better choice over the for loop, but it works if done right.
Just my thoughts on your code.
I am nor sure what the best search words would be, but there are many examples here of C++ code that on the sme type of program you could look at.
Hope that helps,
Andy