views:

49

answers:

2
    #include <iostream>
    #include <fstream>
    using namespace std;
    int calculate_total(int exam1[], int exam2[], int exam3[]); // function that calcualates grades to see how many 90,80,70,60

    int exam1[100];// array that can hold 100 numbers for 1st column
    int exam2[100];// array that can hold 100 numbers for 2nd column
    int exam3[100];// array that can hold 100 numbers for 3rd column 

// here i am passing an array into the function calcualate_total
    int calculate_total(exam1[],exam2[],exam3[])
    {
     int above90=0, above80=0, above70=0, above60=0;
     if((num<=90) && (num >=100))
     {
      above90++;
      {
       if((num<=80) && (num >=89))
       {
        above80++;
        {
         if((num<=70) && (num >=79))
         {
          above70++;
          {
           if((num<=60) && (num >=69))
           {
            above60++;
           }
          }
         }
        }
       }
      }
     }
    }
+1  A: 

By the pointer to int array. (here is definition)

int calculate_total(int *exam1, int *exam2, int *exam3)

If you want call this function, you must in each argument push the address of examX array starting. If you want get element, you must add to the staring array address, a element offset address and get value from her.

Svisstack
The original prototype already declares a function taking `int*` - for parameters, the first dimension always decays.
Georg Fritzsche
A: 

use a vector. you can initialize a vector like an array. the vector has a method to give you the number of elements

zumalifeguard
Guess vector is not the thing for this kind of homework, because using STL without knowing about plain pointers is crap
Kotti
yep havent learned about vectors we are just on arrays in C++, im learning how to read a file into an array. i would love to see the syntex for this and see if i can figure it out from that
Inside the function call, at runtime, you only have a pointer, so there's no way to tell how many elements are in the array. There's no definition at runtime.The only thing that comes close is if you create a specific array type like this:typedef int IntArr50[50];declare your parameters as IntArr50Then in the function do sizeof( IntArr50 / sizeof(int) ) to determine the size. But that will always return 50 because you're deriving the info statically, from the type.Other than that, there's just now ay to do this.
zumalifeguard