can someone explain this to me?

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • kandigirl2009
    New Member
    • Feb 2008
    • 4

    can someone explain this to me?

    I'm a beginner in C++ and my teacher is not explaining the material correctly. I was wondering if I could get help
  • Laharl
    Recognized Expert Contributor
    • Sep 2007
    • 849

    #2
    What problem are you having? What material is he not explaining well? We're gonna need more information than that to help you...

    Comment

    • kandigirl2009
      New Member
      • Feb 2008
      • 4

      #3
      i'm in deltamami's class and this is what the teacher told us about those problems: well, about number one

      first of all... this should not be a main( ) function...

      second... the function should have an array passed to it (by passing a pointer to the first element), and an integer value that you will search for in the array, and one other variable that you will need for the loop control

      third... the function should return a pointer to the value in the array

      How will you find the value in the array? Loop through the array and compare each value to the value you are looking for. When you find the value, return the address of the value in the array (the location of the first element of the array plus the number of ints from the beginning of the array).

      I dont understand what this means
      Originally posted by Laharl
      What problem are you having? What material is he not explaining well? We're gonna need more information than that to help you...

      Comment

      • kandigirl2009
        New Member
        • Feb 2008
        • 4

        #4
        is this right?
        [CODE=cpp]void loadArray(const int*, const int);
        int main()
        {
        //Declare variables
        int myArray[5]; //IN: holds the array of integers
        loadArray(myArr ay, 5); //IN: invokes loadArray




        system("pause") ;
        return 0;

        }

        void loadArray(const int *myArray, const int size)
        {
        //Increments the address
        for(int i = 0; i< size; i++)
        cout<<(myArray+ i)<<endl; //My array is incremented and therefore prints out
        //the information in the array

        }[/CODE]


        Originally posted by kandigirl2009
        i'm in deltamami's class and this is what the teacher told us about those problems: well, about number one

        first of all... this should not be a main( ) function...

        second... the function should have an array passed to it (by passing a pointer to the first element), and an integer value that you will search for in the array, and one other variable that you will need for the loop control

        third... the function should return a pointer to the value in the array

        How will you find the value in the array? Loop through the array and compare each value to the value you are looking for. When you find the value, return the address of the value in the array (the location of the first element of the array plus the number of ints from the beginning of the array).

        I dont understand what this means
        Last edited by Ganon11; Feb 15 '08, 02:51 PM. Reason: Please use the [CODE] tags provided.

        Comment

        • Ganon11
          Recognized Expert Specialist
          • Oct 2006
          • 3651

          #5
          Why not put it into a compiler and see what happens? I don't think you'll get quite what you want.

          Alo, that function looks like it's trying to print the array - but the function name is loadArray - shouldn't you be inputting?

          Comment

          Working...