Thread: expected primary-expression before 'float' and expected ';' before 'float'

  1. #1
    Registered User
    Join Date
    Feb 2013
    Posts
    54

    expected primary-expression before 'float' and expected ';' before 'float'

    Hi,I have 2 errors on the same line while compiling this code, I know itmay be some common beginners errors. Thank you in advance to any onewho may help me
    Code:
    
    
    Code:
    #include <iostream>     
    #include <iomanip>       
    #include <cstdlib>      
    using namespace std;
    float grilletest[20][20];
    
    float initialisation_grille()
    {
       float grille[20][20];
       int ligne ; int colonne ;
       for ( ligne = 0 ; ligne <= 20 ; ligne ++ )
            {  for ( colonne  = 0 ; colonne <= 20 ; colonne ++ )
                        {  grille [ ligne ] [ colonne ] = '0' ;
                            }
    
    
                    }
    return grille[20][20];
    }
    
    void affichage_grille ( float grilletest[20][20] ) { 
    float toto[20][20];                                                                   
    toto= float initialisation_grille();
    
    
     int ligne ;
     int colonne ;
     for ( ligne = 20; ligne >=0 ; ligne --){
                                                for ( colonne = 0 ; colonne <= 20; colonne ++ ){
                                                cout<< toto [ ligne ] [ colonne]<<'\t' ;
                                                        }
          cout << endl ;
        }
    }
    
    
    
    
    int main(){
    float tata[20][20];
    initialisation_grille();
    affichage_grille (tata);
    }

  2. #2
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    39,661
    1. Your indentation needs work.
    Code:
    #include <iostream>
    #include <iomanip>
    #include <cstdlib>
    using namespace std;
    float grilletest[20][20];
    
    float initialisation_grille()
    {
      float grille[20][20];
      int ligne;
      int colonne;
      for (ligne = 0; ligne <= 20; ligne++) {
        for (colonne = 0; colonne <= 20; colonne++) {
          grille[ligne][colonne] = '0';
        }
      }
      return grille[20][20];
    }
    
    void affichage_grille(float grilletest[20][20])
    {
      float toto[20][20];
      toto = float initialisation_grille();
    
      int ligne;
      int colonne;
      for (ligne = 20; ligne >= 0; ligne--) {
        for (colonne = 0; colonne <= 20; colonne++) {
          cout << toto[ligne][colonne] << '\t';
        }
        cout << endl;
      }
    }
    
    int main()
    {
      float tata[20][20];
      initialisation_grille();
      affichage_grille(tata);
    }
    2. What's this supposed to be?
    toto = float initialisation_grille();

    No, you can't return a whole array and assign it to another array.

    If you want to initialise your array, pass it as a parameter.

    3. for (ligne = 0; ligne <= 20; ligne++)
    All your loops are array overruns.

    Typically, you do
    for (ligne = 0; ligne < 20; ligne++) // NOT <=
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. expected primary-expression before ']'
    By ooopa in forum C++ Programming
    Replies: 4
    Last Post: 11-14-2011, 09:35 AM
  2. Expected primary expression
    By MarlonDean in forum C++ Programming
    Replies: 2
    Last Post: 06-20-2008, 03:43 PM
  3. expected primary expression
    By lilhawk2892 in forum C++ Programming
    Replies: 10
    Last Post: 11-22-2007, 07:50 PM
  4. Expected primary expression?
    By Beowolf in forum C++ Programming
    Replies: 17
    Last Post: 11-11-2007, 09:57 PM
  5. expected primary expression
    By mju4t in forum C Programming
    Replies: 2
    Last Post: 03-27-2007, 06:59 PM