944,052 Members | Top Members by Rank

Ad:
  • C++ Discussion Thread
  • Unsolved
  • Views: 4460
  • C++ RSS
Feb 20th, 2005
0

Random Different Number in each loop ?? HLP Me PLZ (c or c++)

Expand Post »
so i have 4 integer that are
int m = rand() % 3+ 0;
int n = rand() % 3 + 0;
int x = rand() % 3 + 0;
int y = rand() % 3 + 0;

and i want to random in 0-3 range so how can i random 4 interger
in different number between 0 - 3 ?? what is loop for this problem ?

exam. Firsttime ; m = 1
n = 0
x = 3
y =2

this is my old code

C++ Syntax (Toggle Plain Text)
  1. int main()
  2. {
  3. srand(time(NULL));
  4. int array[4];
  5. array[0]=rand() % 3 + 0;
  6. for(int i=1;i<=3;i++)
  7. {
  8. array[i]=rand() % 3 + 0;
  9. if ((array[i]=array[i-1])||(array[i]=array[i-2])||(array[i] =array[i-3]))
  10. {
  11. array[i]=rand() % 3 + 0;
  12. }
  13. }
  14. cout<<array[0]<<array[1]<<array[2]<<array[3]<<endl;
  15. system("pause");
  16. return 0;
  17. }

ps.- Use in c or c++
Thank you.
Last edited by alc6379; Feb 23rd, 2005 at 4:44 pm. Reason: added [code] tags
Similar Threads
Reputation Points: 10
Solved Threads: 0
Newbie Poster
s47221288 is offline Offline
4 posts
since Feb 2005
Feb 20th, 2005
0

Re: Random Different Number in each loop ?? HLP Me PLZ (c or c++)

Quote ...
if ((array[i]=array[i-1])||(array[i]=array[i-2])||(array[i] =array[i-3]))
You probably want to use == instead of =. The former is comparison and the latter is assignment. Aside from that, your loop seems to work okay. What exactly are you trying to do?
Reputation Points: 12
Solved Threads: 2
Light Poster
Siersan is offline Offline
45 posts
since Jan 2005

This thread is more than three months old

No one has posted to this discussion for at least three months. Please let old threads die and do not reply to them unless you feel you have something new and valuable to contribute that absolutely must be added to make the discussion complete. Otherwise, please start a new thread in this forum instead.
Message:
Previous Thread in C++ Forum Timeline: Trying to remember !@#$%#
Next Thread in C++ Forum Timeline: String Alphabetize





About Us | Contact Us | Advertise | Acceptable Use Policy
Forum Index | Build Custom RSS Feed


Follow us on Twitter


© 2011 DaniWeb® LLC