c++ - expected primary-expression before ']' token" -


//purpose: simulate probability car make decision in video game. //40% of time car turn left, 30% right, 20% straight, , 10% explode.  #include <iostream> #include <cstdlib> #include <time.h> #include <iomanip>  using namespace std;  void getcount( count[] );  int main() {   int count[4] = {0};   unsigned int k;   float theoretical;    srand( (unsigned) time(null) );    getcount( int count[] );    cout.setf( ios::showpoint | ios::fixed );   cout << setprecision(2);   cout << "                                 car simulation" << endl << endl        << "                number of        experimental        theoretical    % error  " << endl        << "             times selected        percent             percent               " << endl        << "            ----------------    --------------      -------------    ------  " << endl;    ( k = 0; k < 4; k++ )   {       switch(k)       {           case 0:               cout << "left:     ";               theoretical = 40;               break;           case 1:               cout << "right:    ";               theoretical = 30;               break;           case 2:               cout << "straight: ";               theoretical = 20;               break;           default:               cout << "explosion:";               theoretical = 10;               break;       } // end switch              cout << setw( 12 ) << count[ k ]                  << setw( 20 ) << count[ k ] / 10000.0 * 100.0                 << setw( 19 ) << theoretical                  << setw( 13 ) << ( ( count[ k ] - theoretical * 100 ) / (theoretical * 100) * 100 )               << endl << endl;   } //end   cout << endl << endl;  system("pause"); return 0;  } //end main  void getcount( int count[] ) {     int randnum;     unsigned int k;     for( k = 0; k < 10000; k++ )//generates random number 1-100 10,000 times    {       randnum = rand() % 100 + 1;        if( randnum <= 100 && randnum > 60 )            count[0]++;        else if( randnum <= 60 && randnum > 30 )            count[1]++;        else if( randnum <= 30 && randnum > 10 )            count[2]++;        else             count[3]++;    }//end  }//end function definition 

the code above made simulate car making decisions in video game.

at intersection, 40 % of time car turn left, 30% right, 20% straight, , 10% of time car explode.

the program executes 10,000 of these decisions , outputs results.

everything works great except function "getcount()". function, when called, supposed generate random numbers representing decisions , store amount of times each numbers generated in array.

however, when compile program, error saying:

"in line 21, expected primary-expression before ']' token". 

this same line call function. have tried few things try , fix keep getting error.

any advice appreciated, thank you.

getcount( int count[] ); 

should be

getcount(count); 

the type doesn't have repeated; compiler knows count same variable declared int[].


Comments

Popular posts from this blog

apache - Remove .php and add trailing slash in url using htaccess not loading css -

javascript - jQuery show full size image on click -