Newbee

I am new to programing and just want to share my first very small guess a number program and get some suggestion on it. There is one other thing I am using Bloodsheed Dev C++ and it come up with these errors at the bottom of the screen when compling but the .exe still works fine

Code:

////////////////////////////////////////////////////////////////////////////////
//
// langue C++
// Pogram Computer generates number and user trys to guess it
//
////////////////////////////////////////////////////////////////////////////////
#include <iostream.h> //Main include basic funcitions
#include <string.h> //For use of stings
#include <stdio.h> //??????
int main()
{
int number; //"number" variable use to save the users number
int answer; //"answer" variable use to save if the player wants to try agin 1=Yes 2=No
int round; //"round" variable use to save how many times the player has tryed to gues there is only 5 chances
char name[20]; //"name" is a string that saves the players name and makes the game more customized
int r; //"r" variable is the number that the user is tring to guess
r=rand()%11; //Changes the value of 'r" at random
////////////////////////////////////////////////////////////////////////////////
//
// Cheat Codes
//
////////////////////////////////////////////////////////////////////////////////
{
round=0; //Sets the veriable "round" to 0
cout<<"What is your name: "; //Ask the user to input there name
cin.getline(name, 20, '\n'); //Saves the user input in the variable "name"
if(!strcmpi("Beta", name)) //Tells the computer that if the user input is "Beta" then do the code below it
{
r=5; //Sets the veriable "r" to 5
}
if(!strcmpi("Loser", name)) //Tells the computer that if the user input is "Loser" then do the code below it
{
cout<<"Sorry, "<<name<<" ,no cheating for you. By the way did you chose this name. "; //Prints the texts in "
cin.get (); //Tells the computer to wait until the user to press enter to run the next line of code
return 0; //Tells the computer to end the program
}
}
////////////////////////////////////////////////////////////////////////////////
//
// Guess the Number part
//
////////////////////////////////////////////////////////////////////////////////
do //Tells the computer to do what is blow this if while = what you have put in
{
round++; //Adds 1 to the veriable "round"
cout<<"I am think of a number between 1-10 what is it: ";
cin>>number;
if(number==r)
{
cout<<"Congradulations, "<<name<<" ,you got it right!!!";
cin.get ();
answer=2;
}
else if(number>r)
{
cout<<"1=Yes 2=No"<<endl<<endl<<"Sorry, "<<name<<" ,it was a little to high. Would you like to try agin: ";
cin>>answer;
}
else if(number<r)
{
cout<<"1=Yes 2=No"<<endl<<endl<<"Sorry, "<<name<<" ,it was a little to low. Would you like to try agin: ";
cin>>answer;
}
if(round==5)
{
answer=2;
cout<<"Sorry, "<<name<<" ,that was your last try the answer was "<<r;
cin.get ();
}
}
while (answer==1);
cin.get ();
return 0;
}

If you get compile errors, but your exe still works, that is probably because you are using an old exe from an earlier time when your build succeeded. Try deleting (or moving or renaming) your exe and then compile to see if the build really is successful.

Use the new/correct headers. <iostream.h> is old and non-standard, and <stdio.h> and <string.h> are deprecated. Change them to <iostream>, <cstring> and <cstdio>. That will cause you to have to deal with the std namespace, but if you don't want to worry about it you can just put using namespace std; under the includes on small single file projects like this.

You should #include <cstdlib> (or the deprecated <stdlib.h>), since that is where the rand() function comes from. It might work without it, but you should always include the proper header for the library functions you use.

You might want to seed your random number, or the number will always be the same (8). Use srand(time(0)); and #include <ctime> (or the deprecated <time.h>) to get the time functions. This will make the number truly random.

By doing rand()%11, you are getting a number from 0 to 10, not 1-10 like your menu says.

You need to account for names longer than 19 characters. You have to ignore whatever is in the input after the first 19 characters are read into the name, or that will be used as an answer to your next few questions. Try inputting a name that is 30 characters long and see what happens.