ninjawesome222's Profile User Rating: -----

Reputation: 1 Apprentice
Active Members
Active Posts:
106 (0.06 per day)
27-January 10
Profile Views:
Last Active:
User is offline Feb 12 2014 05:54 PM

Previous Fields

Dream Kudos:

Latest Visitors

Icon   ninjawesome222 has not set their status

Posts I've Made

  1. In Topic: Generate Unique Numbers in C

    Posted 12 Feb 2014

    I am having difficulty generating random numbers that are unique. What I have attempted to do is generate a random number, store it in an array, and then when I generate the next random number, I check each slot of the array for duplicates. However, when I run this code, it still yields duplicates and sometimes there is not output at all. Any help is greatly appreciated.

    Here is my code:
    #include <stdio.h>
    #include <stdlib.h>
    #include <time.h>
    int main (void) {
    	int limit = 4;
    	int students = 5;
    	int exams[4];
    	int class[5] = {1,2,3,4,5};
    	int random;
    	int i, j;
    	int flag = -1;
    	for (i = 0; i < limit; i++) {
    		flag = 1;
    		random = rand() % students;
    		do {
    		for (j = 0; j < limit; j++) {
    			if (class[random] == exams[random]) {
    				j = 0;
    				flag = -1;
    				random = rand() % students;
    			} while (flag == -1);
    			exams[i] = class[random];
    	for (i = 0; i < 4; i++) {
    		printf("%d ", exams[i]);
    	return 0;
  2. In Topic: Generate Unique Numbers in C

    Posted 12 Feb 2014

    View PostCTphpnwb, on 11 February 2014 - 07:05 PM, said:

    Question about your "correct" output: How do you know what student took each exam, and therefore that the student grading it isn't grading their own exam?

    Perhaps my description was not clear enough, my apologies. When the output says student 1 will grade exams 4, 3, 2, and 5, I mean he will be grading student 4's exam, student 3's exam, student 2's exam, and student 5's exam.
  3. In Topic: Accessing Variables from Another Class in Java

    Posted 5 Dec 2012

    View Postjon.kiparsky, on 05 December 2012 - 02:22 PM, said:

    Wasting time. Just declare
    private Videogame[] videogames; // why would this be static???

    at the top level and remove the declaration when you refer to it in main:

    videogames = {videogame1, videogame2}


    Awesome. I had to toy around with it a little to fully understand what I was doing, and now it works. Thanks for your help!
  4. In Topic: Accessing Variables from Another Class in Java

    Posted 5 Dec 2012

    I don't understand what your doing here:
    videogames_ = VideoGame;
    Could you possibly elaborate a little? Thanks.
  5. In Topic: Assigning a Size to an Empty Array in Java

    Posted 18 Sep 2012

    View PostSwiftStriker00, on 18 September 2012 - 04:36 PM, said:

    Thats because the array is null. You haven't even told it to reserve space in memory. If you want to create an array with no objects you can do this:
    courses = new Course[ 10 ]; 

    This will allocate space for 10 courses, remember though, array's are not dynamic so if you want more than ten you will have to account for that.

    Thanks for the simple explanation! my code now operates properly.

My Information

Member Title:
D.I.C Head
Age Unknown
Birthday Unknown

Contact Information



ninjawesome222 hasn't added any friends yet.


ninjawesome222 has no profile comments yet. Why not say hello?