Thread: Help plz :)

  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
    Hurry Slowly vart's Avatar
    Join Date
    Oct 2006
    Location
    Rishon LeZion, Israel
    Posts
    6,788
    All problems in computer science can be solved by another level of indirection,
    except for the problem of too many layers of indirection.
    – David J. Wheeler

  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, 09:54 AM
  3. plz help me with simple string comparison.
    By MegaManZZ in forum C++ Programming
    Replies: 11
    Last Post: 02-18-2008, 01: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