need english

Getting ready to work on another lab for school and I'm having trouble understanding the lab. This is the program they want me to write:

Write a program that declares two twenty-element, one-dimensional integer arrays. Your program should fill these arrays with random numbers by calling a function called Fill_It. You will call Fill_It twice, once for each array, and ask the user to enter two different seed values. Fill_It needs to have a seed value, and low and high range values, and all three integers should be passed to it along with the array. Fill_It will use the seed for srand and then fill the arrays with values between the low and high range. Call Fill_It so that it fills one array with values between 1000 and 2000 and call it again so the range is 0 to 1000. Once both arrays are filled, print them to a data file showing the seed value and the twenty elements.

I understand up to the point where I enter two different seed values, but I don't understand how I'm supposed to make one function do two different things, (being filling one array with numbers between 0 to 1000 and the other array 1000 to 2000). I couldn't get a hold of the teacher to clarify this for me, so I figured someone who knows the language would understand this problem. I know basically fill two twenty element one dimensional arrays and show them on the screen, just need help on the Fill_It function. Thanks in advance,
                                       Tony



Answer this question

need english

  • Mark Allen 50

    lol, yeah, nowhere near looking for a handout. I just didn't understand the situation. I have a partial solution, I think anyway. I have the program written, but when I run the program several times, it keeps generating the same numbers, (random numbers, just not random everytime I run it), below is the program:

    //Chapter 6 problem 22 page 249
    #include <iostream.h>
    #include <stdlib.h>
     
     int arrayOne[20];
     int seed=0; 
     int Fill_It(int);

    int main()
    {
     
     int i;
     srand(seed);
     
     cout << "\n Please enter value for seed 1.";
     cin >> seed;
      
     Fill_It(seed);
     
     for(i=0; i<20; ++i)
     {
      cout << arrayOneIdea << endl;
     }

     cout << "\n Please enter value for seed 2.";
     cin >> seed;
      
     Fill_It(seed);
      
     for(i=0; i<20; ++i)
     {
      cout << arrayOneIdea+1000 << endl;
     }
     
     return 0;
    }
    /*====================================================================*/

    int Fill_It(int seed)

    {
     int i, rand_num;
     for(i=0; i<20; ++i)
     {
      rand_num=rand()%1000;
      arrayOneIdea=rand_num;
     }
     return arrayOneIdea;
    }

    I apologize for the misunderstanding, I was only looking for clarification of the problem and a general understanding of it, not a handout. I can't get anywhere and understand any of this if I have someone do it all for me. Thanks
                Tony


  • Valcom

    And how do I get rid of those lightbulbs in my code, lol
  • YarakMan

    I think I understand you right, this is what I have below:

    //Chapter 6 problem 22 page 249
    #include <iostream.h>
    #include <stdlib.h>
     
     
     int seed=0; 
     void Fill_It(int []);

    int main()
    {
      
     int i, arrayOne[20];;
     
     cout << "\n Please enter value for seed 1.";
     cin >> seed;
      srand(seed);

     Fill_It(arrayOne);
     
     for(i=0; i<20; ++i)
     {
      cout << arrayOneIdea << endl;
     }

     cout << "\n Please enter value for seed 2.";
     cin >> seed;
      srand(seed);

     Fill_It(arrayOne);
      
     for(i=0; i<20; ++i)
     {
      cout << arrayOneIdea+1000 << endl;
     }
     
     return 0;
    }
    /*====================================================================*/

    void Fill_It(int arrayOne[])

    {
     int i, rand_num;
     for(i=0; i<20; ++i)
     {
      rand_num=rand()%1000;
      arrayOneIdea=rand_num;
     }
    }

    I did get the random to work off the seed value and they change like they're suppose to now, I think, lol. I didn't use the indirection operator in the declaration, I tried but kept getting an error, but now when I run the program it asks for the first seed value, then displays the array elements, then it asks for the second seed value, displays the elements and very quickly exits the program. This is the message I keep getting:

    Loaded 'ntdll.dll', no matching symbolic information found.
    Loaded 'C:\WINDOWS\system32\kernel32.dll', no matching symbolic information found.
    The thread 0xF50 has exited with code 0 (0x0).
    The program 'F:\C++\chap6p22\Debug\chap6p22.exe' has exited with code 0 (0x0).

    What does this mean


  • Paulius

    Sorry to be blunt but this is not a "please do my homework for me" forum.

    If you don't understand the assignment then go and talk to your teacher.

    If you want help from this forum then I would suggest that you come up with at least a partial solution by yourself.

  • Tobias Hoff

    You pressed F5 to run the program, and that is the debugger output.  Your program depends on ntdll.dll and kerneldll.dll, and the debugger is simply telling you that it did not find the "program database" (pdb) files associated with these dlls.  This is by design.  You don't have the source code for the OS, hence the pdb files for these dlls are not shipped with Visual Studio.

    You will notice that your program has its own pdb file in the output directory: it is created by the compiler and linker.  This contains information about the program's symbols and line numbers in your code so that stepping through your program while debugging behaves as you expect it to.

    Your program exited normally.  The exit code 0 corresponds to the return 0 from your main function.




  • George1905

    First, you need to call srand each time you get an updated seed value from the user.  However, a typical program only calls srand once.

    If the teacher intended to give an exact specification for the arguments for Fill_It, then he/she made a mistake.  You don't need to pass the seed value to Fill_It (the seed is consumed by srand which, as you've coded it, is outside Fill_It), but you do need to tell it the low value, the high value *AND* the array to fill.  I suggest declaring Fill_it as:

    void Fill_It( int* arrayToFill, int lowValue, int highValue );

    Don't make ArrayOne and ArrayTwo global.  Now is a good time not to pick up bad programming habits.

    Brian

    (I love it when college professors try to teach C/C++ when they suck at it themselves... at my school, one of them said using #define BEGIN { and #define END } makes C coding nicer.)


  • &amp;#21556;&amp;#22521;

    If you want your program to stop before terminating, so that you can look at the output, you could add these lines before returning from main:

    cout << "Hit ENTER to continue" << endl;
    getchar();



  • runar lyngset

    you may want to use different index variable than i.
    arrayOne[j]  as opposed to arrayOneIdea

  • Omer KU?CU

    Oh and the lightbulb was the array index set to a counter "i" but I didn't know it would show a lightbulb, lol, sorry.
  • need english