hi guys am a kenyan and i just got started learning the c++. its awesome.
i have a question i wuld like to ask for answers soon. help me in making a program that will allow the computer to choose any number between one and a hundred then the user has 6 options to guess but after the 6th and the users hasnt gotten it right, the comp displays the correct number. i also need some simple codes coz am new in this game guyz. thanx in advance hope i'll get the answers

Recommended Answers

All 5 Replies

We're not going to give you a complete solution, wouldn't want to spoil your fun by learning how to program it yourself. How much C and/or C++ do you already know? Do you know how to make the program chose a number between 1 and 100? Hint: use the mod % operator and rand() random number generator. Get that part working first and post the code you have written.

@ancient dragon how do we use rand() function in a program?What exactly does it do?

One of the things you need to learn is how to look up the descriptions for functions that you do not understand. google is your best friend for doing that. Example: good for "c++ rand" and you will get this list. Any of the first 6 entries in that list will answer your question for you.

Before calling rand() you need to seed it's random number generator so that rand() will return a different set of numbers each time your program is run. The normal way to do that us by using time() function, which returns the current time in seconds.

#include <cstdlib>
#include <ctime>

int main()
{
    srand( time(0) ); // see random number generator

    int n = rand(); // get a random number

}

If you are using Linux for an OS, the man pages are terribly helpful, such as "man rand". If you aren't running Linux, then you can search the web. In this case, the google search terms "man rand" will point you to a page (many pages) with the same information, and many more pages with totally irrelevant (but interesting) information that matches your search terms! :-)

You can also use a comprehensive c++ reference site like cplusplus.com. It's got its own google search for its site.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.