OK, here is my c++ program that i made with "Visual C++ 2005 Express Edition"....

#include<cstdlib>
#include<ctime>
#include<iostream>
using namespace std;
int main()
{
    cout << "Welcome To Danny's Game!.\n";
    cout << "See if you can beat me.\n";
    cout << "The First number below is your number.\n";
    srand((unsigned)time(0));
    int random_integerplayer;
    for(int index=0; index<1; index++)
    {
        random_integerplayer = (rand()%10)+1;
        cout << random_integerplayer << endl;
        cout << "\n";
        cout << "This is my number.\n";
        srand((unsigned)time(0));
        int random_integercomputer;
        for(int index=0; index<1; index++)
        {
            random_integercomputer = (rand()%10)+1;
            cout << random_integercomputer << endl;
            cout << "\n";
            if( random_integercomputer>=random_integerplayer )
                cout << "You Lose. ";
            else
                cout << "You Win! ";
        }
    }
}

OK, that was my code, but something won't work.
Whenever i use it, it always comes up with 2(two)
numbers(computer and player), that are both exactully the same!!!
Please help me make it so that when it generates the random numbers, they are both different...
thxz alot! =)

Member Avatar for iamthwee

please use code tags

It is because you are reseeding the random number generator and in the attempt restarting it. You need to seed the random number generator only once for a single run. Remove the second instance of srand( ( unsigned ) time( 0 ) ) and you should be fine.

And btw, what's up with the redundant loops ? Maybe you wanted to make the program loop infinitely and to exit based on the choice entered by the user ? You can try something like:

int choice = 1 ;
while( choice )
{
    // your code here

   cout << "Do you want to continue ? ( 0 to exit ) " ;
   cin >> choice ;
}

And yeah, use proper code tags, don't color your code, the highlighting is automatically taken care by the code tags. Just paste your code within code tags.

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.