Warning

 

Close
Confirm Action

Are you sure you wish to do this?

Cancel Confirm
AR15.COM
Previous Page
/ 2
Next Page
3/6/2009 8:34:46 AM EDT
http://rafb.net/p/Y8lYQ538.html

Alright this has no syntax errors at all. But I dont think the number generator is working correctly.

I dont think the number are being generated therefor not going through the counters.

Anyone got any advice on making the number generator work?
3/6/2009 8:36:25 AM EDT
[#1]
waiting for someone to confirm this is a legit link/post.

why don't you just post your source code.
3/6/2009 8:38:03 AM EDT
[#2]
didnt wannafill up the thread, its from no paste its easier to read in there
3/6/2009 8:38:39 AM EDT
[#3]
#include <stdio.h>
#include <stdbool.h>
#include <stdlib.h>

//Function Declarations
void displayName (void);
bool getInput (int *seed, int *lb, int *ub, int *numToGen);
bool getSeed (int *seed);
bool getBounds (int *lb, int *ub);
bool getNumToGen (int *numToGen);
bool genRandom (int seed, int lb, int ub, int numToGen, int *randNum
              int *even, int *odd, int *neg, int *pos, int *zero);
bool addToCounts (int randNum, int *even, int *odd,
                int *neg, int *pos, int *zero);
void printResults (int seed, int lb, int ub, int numToGen, int randNum,
                 int even, int odd, int neg, int pos, int zero);


int main (void)


{
  //Local Declarations
  int seed, lb, ub, numToGen, randNum;
  int even = 0;
  int odd = 0;
  int neg = 0;
  int pos = 0;
  int zero = 0;

  //Statements
  displayName ();
  getInput (&seed, &lb, &ub, &numToGen);
  genRandom (seed, lb, ub, numToGen, &randNum,
              &even, &odd, &neg, &pos, &zero);
  addToCounts (randNum, *even, *odd, *neg, *pos, *zero);
  printResults (seed, lb, ub, numToGen, randNum, even, odd, neg, pos,
                zero);




  return 0;
}

void displayName (void)
{
  printf("Name: John Doe");
  printf("\n\n");
}

bool getInput (int *seed, int *lb, int *ub, int *numToGen)
{
  getSeed(seed);
  getBounds(lb, ub);
  getNumToGen(numToGen);
}

bool getSeed (int *seed)
{              
  int input;

  printf("Please enter a nonnegative seed value: ");
  scanf("%d", &input);

  if (input < 0)
     {
      printf("%d is not nonnegative.");
          printf("Please try again another day.");
 }  
  else
     {
      *seed = input;
 }
  printf("\n\n");
}

bool getBounds (int *lb, int *ub)
{
  int input1, input2;

  printf("Please enter a lower bound [-25,-1] and an upper bound [1,25]: ");
  scanf("%d %d", &input1, &input2);

  if (input1 < -25)
     {
      printf("Lower bound %d is not in the range [-25,-1].");
          printf("Please try again another day.");
     }
  else if (input1 > -1)
     {
      printf("Lower bound %d is not in the range [-25,-1].");
          printf("Please try again another day.");
     }
  else
     {
      *lb = input1;
     }

  if (input2 < 1)
     {
          printf("Upper bound %d is not in the range [1,25].");
          printf("Please try again another day.");
     }
  else if (input2 > 25)
     {
      printf("Upper bound %d is not in the range [1,25].");
          printf("Please try again another day.");
     }
  else
     {
      *ub = input2;
     }

  printf("\n\n");
}
bool getNumToGen (int *numToGen)
{
  int input;

  printf("Please enter the number of randoms to generate [10,50]: ");
  scanf("%d", &input);

  if (input < 10)
     {
      printf("%d is not in the range [10,50].");
          printf("Please try again another day.");
     }
  else if (input > 50)
     {
      printf("%d is not in the range [10,50].");
          printf("Please try again another day.");
     }
  else
     {
      *numToGen = input;
     }

  printf("\n\n");
}

bool genRandom (int seed, int lb, int ub, int numToGen, int *randNum)
{
  int range;
  int i;

  srand(seed);
  range = (ub - lb) + 1;

  for (i = 10; i < numToGen; i++)
  {
     *randNum = lb + rand() % range;
  }
}

bool addToCounts(int randNum, int *even, int *odd,
                int *neg, int *pos, int *zero)
{  
  if (randNum < 0)
    {
    *neg++;
    }
  else if (randNum > 0)
    {
    *pos++;  
    }
  else    
    {
    *zero++;
    }

  if (randNum != 0)
     {    
      if (randNum % 2 == 0)
     {
     *even++;
     }
     }
  else
    {
    *odd++;
    }

}

void printResults(int seed, int lb, int ub, int numToGen, int randNum,
                 int even, int odd, int neg, int pos, int zero)
{
  printf("\n%15s%15s%15s%15s", "Input Type", "Value",
         "Count Type", "Value");
  printf("\n%15s%15s%15s%15s", "––––––––––", "––––-",
         "––––––––––", "––––-");
  printf("\n%15s%15d%15s%15d", "Seed", seed, "Evens", even);
  printf("\n%15s%15d%15s%15d", "Lower Bound", lb, "Odds", odd);
  printf("\n%15s%15d%15s%15d", "Upper Bound", ub, "Negatives", neg);
  printf("\n%15s%15d%15s%15d", "Number Generated", numToGen,
         "Positives", pos);
  printf("\n%15s%15s%15s%15d", "", "", "Zeros", zero);
  printf("\n\n");
}
3/6/2009 8:39:15 AM EDT
[#4]
theres the source code.

Any help would be greatly appreciated
3/6/2009 8:41:47 AM EDT
[#5]
i havent looked at C code in over 10 years.

do you have a debugger. walking through it line by line in the debugger should be able to help you identify your problem.
3/6/2009 8:48:27 AM EDT
[#6]
wish subnet was around here
3/6/2009 8:49:24 AM EDT
[#7]
if it was MATLAB code I could help you..
3/6/2009 8:49:47 AM EDT
[#8]
first off why are you having functions return bool values that are never used?

if it has a return value, it should

return _____

something in every possible branch, otherwise it should be void.
3/6/2009 8:49:59 AM EDT
[#9]
Why does genRandom() have 5 parameters in the function declaration but you pass in 10 parameters in the actual call?

Also you don't actually do anything with the random number generated in that function. The integer pointer just gets overwritten 10+ times.
3/6/2009 8:52:08 AM EDT
[#10]
Quoted:
Why does genRandom() have 5 parameters in the function declaration but you pass in 10 parameters in the actual call? Also you don't actually do anything with the random number generated in that function. The integer pointer just gets overwritten 10+ times.



no it has 10, it's just continued on the next line.

yes, the problem seems to be in the getrand funciton.

most likely, as with all C and C++ problems, a pointer or reference issue.

man I'm glad modern languages do all of that for you.


ETA:

to the OP,

I don't see in the final printf where you're displaying the randNum value.
3/6/2009 8:55:24 AM EDT
[#11]
Sorry I copied and pasted that off notepad++ without fixing the last thing I changed.


#include <stdio.h>
#include <stdbool.h>
#include <stdlib.h>

//Function Declarations
void displayName (void);
bool getInput (int *seed, int *lb, int *ub, int *numToGen);
bool getSeed (int *seed);
bool getBounds (int *lb, int *ub);
bool getNumToGen (int *numToGen);
bool genRandom (int seed, int lb, int ub, int numToGen, int *randNum);
bool addToCounts (int randNum, int *even, int *odd,
                int *neg, int *pos, int *zero);
void printResults (int seed, int lb, int ub, int numToGen, int randNum,
                 int even, int odd, int neg, int pos, int zero);


int main (void)


{
  //Local Declarations
  int seed, lb, ub, numToGen, randNum;
  int even = 0;
  int odd = 0;
  int neg = 0;
  int pos = 0;
  int zero = 0;

  //Statements
  displayName ();
  getInput (&seed, &lb, &ub, &numToGen);
  genRandom (seed, lb, ub, numToGen, &randNum);
  addToCounts (randNum, *even, *odd, *neg, *pos, *zero);
  printResults (seed, lb, ub, numToGen, randNum, even, odd, neg, pos,
                zero);
               


             
  return 0;
}

void displayName (void)
{
  printf("Name: John Doe");
  printf("\n\n");
}

bool getInput (int *seed, int *lb, int *ub, int *numToGen)
{
  getSeed(seed);
  getBounds(lb, ub);
  getNumToGen(numToGen);
}

bool getSeed (int *seed)
{              
  int input;
 
  printf("Please enter a nonnegative seed value: ");
  scanf("%d", &input);
 
  if (input < 0)
     {
      printf("%d is not nonnegative.");
          printf("Please try again another day.");
 }  
  else
     {
      *seed = input;
 }
  printf("\n\n");
}
 
bool getBounds (int *lb, int *ub)
{
  int input1, input2;
 
  printf("Please enter a lower bound [-25,-1] and an upper bound [1,25]: ");
  scanf("%d %d", &input1, &input2);
 
  if (input1 < -25)
     {
      printf("Lower bound %d is not in the range [-25,-1].");
          printf("Please try again another day.");
     }
  else if (input1 > -1)
     {
      printf("Lower bound %d is not in the range [-25,-1].");
          printf("Please try again another day.");
     }
  else
     {
      *lb = input1;
     }

  if (input2 < 1)
     {
          printf("Upper bound %d is not in the range [1,25].");
          printf("Please try again another day.");
     }
  else if (input2 > 25)
     {
      printf("Upper bound %d is not in the range [1,25].");
          printf("Please try again another day.");
     }
  else
     {
      *ub = input2;
     }
         
  printf("\n\n");
}
bool getNumToGen (int *numToGen)
{
  int input;
 
  printf("Please enter the number of randoms to generate [10,50]: ");
  scanf("%d", &input);
 
  if (input < 10)
     {
      printf("%d is not in the range [10,50].");
          printf("Please try again another day.");
     }
  else if (input > 50)
     {
      printf("%d is not in the range [10,50].");
          printf("Please try again another day.");
     }
  else
     {
      *numToGen = input;
     }
 
  printf("\n\n");
}

bool genRandom (int seed, int lb, int ub, int numToGen, int *randNum)
{
  int range;
  int i;

  srand(seed);
  range = (ub - lb) + 1;
 
  for (i = 10; i < numToGen; i++)
  {
     *randNum = lb + rand() % range;
  }
}

bool addToCounts(int randNum, int *even, int *odd,
                int *neg, int *pos, int *zero)
{  
  if (randNum < 0)
    {
    *neg++;
    }
  else if (randNum > 0)
    {
    *pos++;  
    }
  else    
    {
    *zero++;
    }
   
  if (randNum != 0)
     {    
      if (randNum % 2 == 0)
     {
     *even++;
     }
     }
  else
    {
    *odd++;
    }
   
}

void printResults(int seed, int lb, int ub, int numToGen, int randNum,
                 int even, int odd, int neg, int pos, int zero)
{
  printf("\n%15s%15s%15s%15s", "Input Type", "Value",
         "Count Type", "Value");
  printf("\n%15s%15s%15s%15s", "––––––––––", "––––-",
         "––––––––––", "––––-");
  printf("\n%15s%15d%15s%15d", "Seed", seed, "Evens", even);
  printf("\n%15s%15d%15s%15d", "Lower Bound", lb, "Odds", odd);
  printf("\n%15s%15d%15s%15d", "Upper Bound", ub, "Negatives", neg);
  printf("\n%15s%15d%15s%15d", "Number Generated", numToGen,
         "Positives", pos);
  printf("\n%15s%15s%15s%15d", "", "", "Zeros", zero);
  printf("\n\n");
}

3/6/2009 8:56:24 AM EDT
[#12]
What is it doing?  You said it isn't working correctly but what are you seeing it do?
3/6/2009 8:56:36 AM EDT
[#13]
And I need to have the randNum print in rows and columns and Im in the process of figuring that our right now.
3/6/2009 8:58:24 AM EDT
[#14]
this is the output so far


Please enter a nonnegative seed value: 45


Please enter a lower bound [-25,-1] and an upper bound [1,25]: -5 5


Please enter the number of randoms to generate [10,50]: 34



         Input Type______Value____Count Type_____Value
         ––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––-
               Seed________45_______Evens_________0
        Lower Bound______-5_______Odds_________0
        Upper Bound_______5________Negatives_____0
   Number Generated____34_______Positives_______0
    ___________________________Zeros__________0
3/6/2009 8:59:57 AM EDT
[#15]
int main (void)


{
//Local Declarations
int seed, lb, ub, numToGen, randNum;
int even = 0;
int odd = 0;
int neg = 0;
int pos = 0;
int zero = 0;

//Statements
displayName ();
getInput (&seed, &lb, &ub, &numToGen);
genRandom (seed, lb, ub, numToGen, &randNum);
addToCounts (randNum, *even, *odd, *neg, *pos, *zero);
printResults (seed, lb, ub, numToGen, randNum, even, odd, neg, pos,
zero);




return 0;
}

Should that RED line be this instead?

addToCounts(randNum, &even, &odd, &neg, &pos, &zero);
3/6/2009 9:02:12 AM EDT
[#16]
oh yea another thing I forgot to change in notepad++ I have it as &
3/6/2009 9:03:14 AM EDT
[#17]
Hey man, I'm a bit busy at present with work, but post your most current source using rafb.net. Don't clutter up the thread with huge dumps, and ignore the guys who won't click the damn link, for whatever reason.



I'll take a look at it, after you've done that.
3/6/2009 9:03:52 AM EDT
[#18]
Shouldn't the call to addToCounts() be inside the for-loop inside genRandom()? Otherwise it's only doing the very last number generated.
3/6/2009 9:05:29 AM EDT
[#19]
Here's one mistake:

if (randNum != 0)
{
if (randNum % 2 == 0)
{
*even++;
}
}
else
{
*odd++;
}


I think you mean to pair that else with the second if and not the first one.
3/6/2009 9:11:02 AM EDT
[#20]
Quoted:
Hey man, I'm a bit busy at present with work, but post your most current source using rafb.net. Don't clutter up the thread with huge dumps, and ignore the guys who won't click the damn link, for whatever reason.

I'll take a look at it, after you've done that.


http://rafb.net/p/XiAXPj25.html

Thank you
3/6/2009 9:12:05 AM EDT
[#21]
Quoted:
Shouldn't the call to addToCounts() be inside the for-loop inside genRandom()? Otherwise it's only doing the very last number generated.



Oh I see what you mean. It needs to count after every loop of the Number generator?

3/6/2009 9:15:11 AM EDT
[#22]
Quoted:
Quoted:
Shouldn't the call to addToCounts() be inside the for-loop inside genRandom()? Otherwise it's only doing the very last number generated.



Oh I see what you mean. It needs to count after every loop of the Number generator?



If you are wanting it to increment the positive, negative, evens and odds and zeros counters after each random number is generated, then yes it needs to be in the loop. Otherwise the way it is now, it only does the last number generated.

3/6/2009 9:21:04 AM EDT
[#23]
Your compiler is not very strict, for grins (and speed) I pasted your code into a file on my computer and attempted to compile it. Lots of errors.

I suggest you start with addressing these:

if a function is declared to return a value, then it should return a value - otherwise declare it as void

you are not passing enough arguments to all of your functions - look at all the printf statements where you have format specifiers for arguments that are never passed
3/6/2009 9:27:56 AM EDT
[#24]
First comment
COMMENT YOUR CODE!

Second: This formating is bad; it makes it difficult to read...
if (randNum < 0)
 {
 *neg++;
 }
Do this
if (randNum < 0)  {
   *neg++;
}

You need \n at the end of your printfs to add a newline character.

Please clean it up and add comments. I am not sure what you want the code to do so it is kinda hard to figure out what might be wrong...
3/6/2009 9:33:06 AM EDT
[#25]
this guy has a problem with his code and your complaining about text formatting?  I bet your a manager
3/6/2009 9:35:53 AM EDT
[#26]
Quoted:
this guy has a problem with his code and your complaining about text formatting?  I bet your a manager

Nope, architect... It was a minor point. The main point (first point) is he needs comments.  If your going to ask for help at least give the people trying to help you a clue as to what is going on/what the code is supposed to do (inputs, outputs, desired results, etc) :)

Example:
bool genRandom (int seed, int lb, int ub, int numToGen, int *randNum){

  int range;
  int i;

  srand(seed);
  range = (ub - lb) + 1;

  for (i = 10; i < numToGen; i++)   {
     *randNum = lb + rand() % range;
  }
}

This loop constantly updates the same variable (randNum) multiple times.
It is not readily apparent if the + or % has precedence (% does obviously)
IS this code supposed to overwrite the value randNum multiple times without it being used? I would assume not but there might be cases where it might be desirable...
If it is desired to keep each of the generated values... then you need to dump them into an array...
bool genRandom (int seed, int lb, int ub, int numToGen, int *randNum[]) {

  int range;
  int i;

  srand(seed);
  range = (ub - lb) + 1;

  for (i = 10; i < numToGen; i++)   {
     *randNum[i-10] = (rand() % range) + lb;
  }
}

But I am not sure if this is what is desired for the function....

(edited to add code)
3/6/2009 9:41:20 AM EDT
[#27]
The code you posted doesnt compile. Change these lines


addToCounts (randNum, *even, *odd, *neg, *pos, *zero);
to
addToCounts (randNum, &even, &odd, &neg, &pos, &zero);

also change all those bool returns to void
3/6/2009 9:43:56 AM EDT
[#28]
I also see a problem with your printf's.   this is probably why you are not seeing a output.

example:
printf("%d is not nonnegative.");

use google to find the correct usage, you probably intend something like this

printf("%d is not nonnegative.", input);
3/6/2009 9:45:43 AM EDT
[#29]
Quoted:
this guy has a problem with his code and your complaining about text formatting?  I bet your a manager


hey no worries, Im learning so any constructive criticism is welcome.
3/6/2009 9:47:24 AM EDT
[#30]
Quoted:
I also see a problem with your printf's.   this is probably why you are not seeing a output.

example:
printf("%d is not nonnegative.");

use google to find the correct usage, you probably intend something like this

printf("%d is not nonnegative.", input);



AHHHH that is genius, I was wondering why it would throw up 0's
3/6/2009 9:52:56 AM EDT
[#31]
Quoted:
I also see a problem with your printf's.   this is probably why you are not seeing a output.

example:
printf("%d is not nonnegative.");

use google to find the correct usage, you probably intend something like this

printf("%d is not nonnegative.", input);



Alright Finished this, now it prints wrong numbers too
3/6/2009 9:54:18 AM EDT
[#32]
For each function, please add the following comment structure

// This function does X
// Inputted values are:
// List them, and their possible rages/values
// The result of the function is:
// The return value is:

With this, a person reading your code (including yourself) knows what the function should do, what the inputs are and what the desired output / end results should be.
This will also help you. You can write all your program with just function stubs because you have told yourself exactly how the functions will behave, you just need to add the behavior later.

Oh, also, if you want to learn some more :) rand() sucks for its psuedorandomness. http://en.wikipedia.org/wiki/Pseudorandom_number_generator I have always liked the Mersenne twister with some of my own bit shifting mods.
3/6/2009 9:54:41 AM EDT
[#33]
Quoted:
Quoted:
this guy has a problem with his code and your complaining about text formatting?  I bet your a manager

Nope, architect... It was a minor point. The main point (first point) is he needs comments.  If your going to ask for help at least give the people trying to help you a clue as to what is going on/what the code is supposed to do (inputs, outputs, desired results, etc) :)

Example:
bool genRandom (int seed, int lb, int ub, int numToGen, int *randNum){   int range;   int i;    srand(seed);   range = (ub - lb) + 1;    for (i = 10; i < numToGen; i++)   {      *randNum = lb + rand() % range;   }}

This loop constantly updates the same variable (randNum) multiple times.
It is not readily apparent if the + or % has precedence (% does obviously)
IS this code supposed to overwrite the value randNum multiple times without it being used? I would assume not but there might be cases where it might be desirable...
If it is desired to keep each of the generated values... then you need to dump them into an array...
bool genRandom (int seed, int lb, int ub, int numToGen, int *randNum[]) {   int range;   int i;    srand(seed);   range = (ub - lb) + 1;    for (i = 10; i < numToGen; i++)   {      *randNum[i-10] = (rand() % range) + lb;   }}

But I am not sure if this is what is desired for the function....

(edited to add code)


Only problem is I cant use arrays. Has to be Boolean loops

3/6/2009 9:56:50 AM EDT
[#34]
Ok, in the function
bool genRandom (int seed, int lb, int ub, int numToGen, int *randNum[])
What are you trying to do?
3/6/2009 9:57:59 AM EDT
[#35]
change
  for (i = 10; i < numToGen; i++)
  {

to  
for (i = 10; i > numToGen; i++)
  {

Also your trying to generate more than one random number into a int.  That isnt going to work and some big changes need made to your code
3/6/2009 10:01:07 AM EDT
[#36]
Quoted:
Ok, in the function
bool genRandom (int seed, int lb, int ub, int numToGen, int *randNum[])
What are you trying to do?



Trying to seed a number(seed), have the upper and lower bounds(ub and lb) within which the generator should be generate numbers, and how many randoms to generate(numToGen).

And I need to print the randoms in 5 rows and 10 columns
3/6/2009 10:07:35 AM EDT
[#37]
I made some changes for you
look at this, look what i changed.  You should be able to fix up whatever else is wrong from here

http://rafb.net/p/SSUvOP53.html

edited to add output from the modified code

D:\temp\test\Debug>test
Name: John Doe

Please enter a nonnegative seed value: 45


Please enter a lower bound [-25,-1] and an upper bound [1,25]: -15
15


Please enter the number of randoms to generate [10,50]: 10



    Input Type          Value     Count Type          Value
    ûûûûûûûûûû          ûûûû-     ûûûûûûûûûû          ûûûû-
          Seed             45          Evens              2
   Lower Bound            -15           Odds              7
   Upper Bound             15      Negatives              5
Number Generated             10      Positives              4
                                       Zeros              1
3/6/2009 10:12:51 AM EDT
[#38]
Quoted:
I made some changes for you
look at this, look what i changed.  You should be able to fix up whatever else is wrong from here

http://rafb.net/p/SSUvOP53.html

edited to add output from the modified code

D:\temp\test\Debug>test
Name: John Doe

Please enter a nonnegative seed value: 45


Please enter a lower bound [-25,-1] and an upper bound [1,25]: -15
15


Please enter the number of randoms to generate [10,50]: 10



    Input Type          Value     Count Type          Value
    ûûûûûûûûûû          ûûûû-     ûûûûûûûûûû          ûûûû-
          Seed             45          Evens              2
   Lower Bound            -15           Odds              7
   Upper Bound             15      Negatives              5
Number Generated             10      Positives              4
                                       Zeros              1




OMG thank you,

Is Malloc an Array though?
3/6/2009 10:13:06 AM EDT
[#39]
Quoted:
Quoted:
Ok, in the function
bool genRandom (int seed, int lb, int ub, int numToGen, int *randNum[])
What are you trying to do?


Trying to seed a number(seed), have the upper and lower bounds(ub and lb) within which the generator should be generate numbers, and how many randoms to generate(numToGen).

And I need to print the randoms in 5 rows and 10 columns


Ok, if I understand you (and I could easily have made a mistake) , then lets try this.... (You need to add the code :)
// This prints the values as it generates them
// assuming numToGen is less than 50
// if it is more, only 50 rands will print
//seed a number

// calculate the bounds differential...
// lower - upper is the diff

// loop 5 times for 5 rows
// loop 10 times for 10 columns

// generate a random number, mod it to my range and add the bounds differential value

// print random number and a tab

// increment a counter tracking the number of randoms printed

// if the counter is >= numToGen  then print a newline (\n) and break or return

// end loop 10 times
// print a newline (\n)

// end loop 5 times
// If we got here then numToGen  > 50
// all done

There are your comments... Try adding the code :)
To be even more precise, you will want to subtract from your mod value the range differential. JUST make sure the resulting value is not negative. Always always bound check your values.
3/6/2009 10:15:20 AM EDT
[#40]
Quoted:
OMG thank you,

Is Malloc an Array though?


What we're doing is allocating memory for the random numbers being generated, yes we can treat this memory as an array

3/6/2009 10:16:10 AM EDT
[#41]
Fuckin Nerds
3/6/2009 10:16:58 AM EDT
[#42]
Quoted:
Fuckin Nerds

Geeks! not Nerds
3/6/2009 10:25:44 AM EDT
[#43]
i cant get it to compile
3/6/2009 10:29:01 AM EDT
[#44]
Quoted:
Quoted:
OMG thank you,

Is Malloc an Array though?


What we're doing is allocating memory for the random numbers being generated, yes we can treat this memory as an array




lol im not supposed to use arrays
3/6/2009 10:29:56 AM EDT
[#45]
Quoted:
lol im not supposed to use arrays


I'm not supposed to do your homework
3/6/2009 10:44:03 AM EDT
[#46]
Quoted:
Quoted:
lol im not supposed to use arrays


I'm not supposed to do your homework


Didnt say i didnt appreciate the help, thank you kindly

3/6/2009 10:46:32 AM EDT
[#47]
test.c:161: error: 'for' loop initial declaration used outside C99 mode

any idea what this means
3/6/2009 10:48:32 AM EDT
[#48]
Looks like you are really good with indentation which helps the readability of the code.
3/6/2009 10:49:50 AM EDT
[#49]
Why are you trying to generate all the random numbers inside the getRandom() function? If you're not supposed to use arrays, I suspect the teacher is steering you towards writing a method that generates a single random number between bounds given in the argument. Then use a for loop to call that function however many times you need.

Write functions that do one thing.
3/6/2009 4:32:53 PM EDT
[#50]
Here you go, man. I got a little break at work, today.





I commented the shit out of it (even though the code is obvious

) to indicate what I changed, and why.





http://rafb.net/p/LWkIAo43.html




I really wish you could use arrays, because it would clean the hell up out of the code. Also, there's really no need to use pointers all over the place in this app like you're doing, but I left them anyway. I also fixed it so that if a user enters something invalid, it quits (making the bool return values useful!), since that's what it looks like you wanted it to do. If you don't understand any of it, just ask.



Name: Program n00b

Please enter a nonnegative seed value: 7


Please enter a lower bound [-25,-1] and an upper bound [1,25]: -5 5


Please enter the number of randoms to generate [10,50]: 50


1-10:   -1    2    3   -1   -4    0    1    4    1   -3
11-20:    2   -4   -1    4   -1   -2   -3    5    3   -5
21-30:   -3    0   -5   -3    3   -2    0    2   -2   -3
31-40:    0    2    5   -3   -4   -5    0    0    5   -4
41-50:    2   -1   -3    4   -5    0   -4   -2   -3    2

    Input Type          Value     Count Type          Value
    ––––––––––          ––––-     ––––––––––          ––––-
          Seed              7          Evens             18
   Lower Bound             -5           Odds             25
   Upper Bound              5      Negatives             26
Number Generated             50     Positives             17
                                       Zeros              7


 
Previous Page
/ 2
Next Page