Randomize Varible

This is a discussion on Randomize Varible within the C++ Programming forums, part of the General Programming Boards category; How to randomize new varible? For Example: int r; r = random(); r will be for example 43 so I ...

  1. #1
    Hussa
    Guest

    Randomize Varible

    How to randomize new varible?

    For Example:

    int r;
    r = random();
    r will be for example 43

    so I want varible array become: char hello_43[256];

    Example code please...


    Thanks.

  2. #2
    Skunkmeister Stoned_Coder's Avatar
    Join Date
    Aug 2001
    Posts
    2,572
    not possible.
    variable names are a compile time thing. They cannot be chosen based on runtime decisions.
    Free the weed!! Class B to class C is not good enough!!
    And the FAQ is here :- http://faq.cprogramming.com/cgi-bin/smartfaq.cgi

  3. #3
    Registered User dizolve's Avatar
    Join Date
    Dec 2002
    Posts
    68
    You can't really do that.. unless there are preprocessor directives I'm not aware of. What reason do you have for needing this? Maybe someone can suggest an alternative route for you.

      __               &n bsp;      ___ & nbsp;       &nb sp;       &nbsp ;    
     /\ \  __    &nbs p;           /\_ \      &nbsp ;        & nbsp;     
     \_\ \/\_\  ____     _ __\//\ \    __  __&n bsp;    __   
     /'_` \/\ \/\_ ,`\  / __`\\ \ \  /\ \/\ \  /'__`\ 
    /\ \_\ \ \ \/_/  /_/\ \_\ \\_\ \_\ \ \_/ |/\  __/ 
    \ \___,_\ \_\/\____\ \____//\____\\ \___/ \ \____\
     \/__,_ /\/_/\/____/\/___/ \/____/ \/__/   \/____/
            &n bsp; I have a BAD figlet& nbsp;addiction.

  4. #4
    Cheesy Poofs! PJYelton's Avatar
    Join Date
    Sep 2002
    Location
    Boulder
    Posts
    1,728
    While I don't think this is necessarily a great way to code, you could instead do 2 dimensional arrays.
    Code:
    char hello[100][256];
    int r;
    r = random()%100;  // get number between 0 and 99
    
    hello[r]="whatever";

  5. #5
    Hussa
    Guest

    ...

    Well, How can I use hello[1][256]; with cin.get()?


    For example:
    char wow[256];
    cout <<"Enter your name\n";
    cin.get(wow,256);


    How would I do that if it has wow[1][256] with cin.get?

  6. #6
    Cheesy Poofs! PJYelton's Avatar
    Join Date
    Sep 2002
    Location
    Boulder
    Posts
    1,728
    I believe like this:
    Code:
    char wow[100][256];
    cout <<"Enter your name\n";
    cin.get(wow[1],256);

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. randomize array blackjack c program
    By bazzano in forum C Programming
    Replies: 4
    Last Post: 09-01-2005, 02:05 PM
  2. accessing varible in a c++ class
    By jccharl in forum C++ Programming
    Replies: 1
    Last Post: 03-10-2004, 02:01 PM
  3. Varible is different once returned.
    By epoch in forum C++ Programming
    Replies: 2
    Last Post: 01-04-2003, 01:45 AM
  4. Problem with Visual C++ ( randomize function )!
    By marCplusplus in forum C++ Programming
    Replies: 2
    Last Post: 12-17-2001, 12:01 PM
  5. Randomize Number Function
    By beyonddc in forum C Programming
    Replies: 3
    Last Post: 12-10-2001, 03:31 AM

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