Help plz :)

This is a discussion on Help plz :) within the C Programming forums, part of the General Programming Boards category; I am trying to write a random number generator...But it keeps spitting out the same three numbers . What am ...

  1. #1
    Registered User
    Join Date
    Jan 2007
    Posts
    89

    Help plz :)

    I am trying to write a random number generator...But it keeps spitting out the same three numbers . What am I doing wrong?

    Code:
    #include <cstdlib>
    #include <iostream>
    
    using namespace std;
    
    int main(int argc, char *argv[])
    {
    int defRand;
    char answer;
    int x;
            for(x = 1; x <= 3;)
            {
                  defRand = 1 + rand() % (10 - 1 + 1);
                  cout << defRand << endl;
                  cout << "Do you accept this value?: \n" << "Enter 'Y' for yes"
                       << " and 'N' for no.";
                  cin  >> answer;
                  
                  if(answer == 'Y' || answer == 'y')
                  {
                            break;
                            }
                  else
                       {    
                            x++;
                       }
                            }
        system("PAUSE");
        return EXIT_SUCCESS;
    }

  2. #2
    Registered User
    Join Date
    Jan 2007
    Posts
    89
    oops wrong board!!

  3. #3
    CSharpener vart's Avatar
    Join Date
    Oct 2006
    Location
    Rishon LeZion, Israel
    Posts
    6,473
    The first 90% of a project takes 90% of the time,
    the last 10% takes the other 90% of the time.

  4. #4
    Registered User
    Join Date
    Jan 2007
    Posts
    89

    Talking

    Got it!! Thanks

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. can any1 plz make this assignment
    By jean in forum C Programming
    Replies: 17
    Last Post: 05-13-2009, 09:19 PM
  2. [Request] Need Help Plz
    By TylerD in forum Tech Board
    Replies: 4
    Last Post: 01-03-2009, 08:54 AM
  3. plz help me with simple string comparison.
    By MegaManZZ in forum C++ Programming
    Replies: 11
    Last Post: 02-18-2008, 12:11 PM
  4. Anyone plz help me
    By Rose_Flowers in forum A Brief History of Cprogramming.com
    Replies: 1
    Last Post: 09-17-2003, 12:01 PM
  5. help plz plz
    By nsssn73 in forum C++ Programming
    Replies: 2
    Last Post: 06-03-2002, 08:44 AM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21