You are here:

C++/I need to make a program using rand()

Advertisement


Question
Hello I need the code to make program so that the user has to guess the computer generated random number HELP!  I need it ASAP!  I use unix ftp

Answer
Hello,

This problem is actually a simple one. The following code should help you out some and get you on track:

// in main
int main()
{
int num = rand();
int choice;
while(true)
{
cout << "Enter the number: ";
cin >> choice;

if(choice == num)
{
cout << "Winner!\n";
break;
}
else
cout << "Incorrect. Guess Again\n";
}
}

Yeah, that should be about it. If you have any other questions or if I didn't state something correctly, please feel free to ask me another question.

I hope this information was helpful.

- Eddie

C++

All Answers


Answers by Expert:


Ask Experts

Volunteer


Eddie

Expertise

I can answer questions about the C++ language, object oriented design and architecture. I am knowledgable in a lot of the math that goes into programming, and am certified by ExpertRating.com. I also know a good deal about graphics via OpenGL, and GUIs.

Experience

I have completed numerous games and demos created with the C++ programming language. Currently employed as a software engineer in the modeling and simulation field. I have about 7 years experience.

©2016 About.com. All rights reserved.