Thread: Random problem (yes.. again :)

  1. #1
    Registered User Spectrum48k's Avatar
    Join Date
    May 2002

    Random problem (yes.. again :)

    i am trying to eliminate zeros and have no duplicate numbers on each line. this is where i am at now with no success. any help will be appreciated. i dont want to use 'goto' .


    #include <stdlib.h>
    #include <time.h>
    #include <iostream>
    using namespace std;
    int main()
    	int number[10], i, j, k;
    	for(j=1; j<10; j++){
    		for(i=0; i<10; i++){
    			number[i] = rand()%50;
    			for(k=0; k<i; k++){
    				if(number[i] != number[k] && number[i] != '0')
    				else if(number[i] == number[k] || number[i] == '0')
    					number[i] = rand()%50;
    			cout << number[i] << ' ';
    		cout << '\n';
    return 0;

  2. #2
    It's full of stars adrianxw's Avatar
    Join Date
    Aug 2001
    number[i] = rand()%49 +1; // ?
    Wave upon wave of demented avengers march cheerfully out of obscurity unto the dream.

  3. #3
    Registered User HaLCy0n's Avatar
    Join Date
    Mar 2003
    Just to be alittle anal, you used the correct iostream header, but still used the depreceated headers for time and stdlib You should be using ctime and cstdlib for C++.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Problem with random numbers
    By yaya in forum C++ Programming
    Replies: 6
    Last Post: 05-30-2007, 10:30 AM
  2. Random Numbers...Problem With FAQ Answer
    By sitestem in forum C++ Programming
    Replies: 12
    Last Post: 04-14-2004, 09:22 AM
  3. problem with random integer
    By techno logic in forum C++ Programming
    Replies: 1
    Last Post: 10-07-2002, 02:20 PM
  4. random problem
    By niroopan in forum C++ Programming
    Replies: 1
    Last Post: 10-02-2002, 02:39 PM
  5. Random things are fine, just one problem with them.
    By DarkSFK in forum C++ Programming
    Replies: 14
    Last Post: 08-19-2002, 08:40 AM