Thread: error C2448: function-style initializer appears to

  1. #1
    Registered User
    Join Date
    Oct 2010
    Posts
    1

    error C2448: function-style initializer appears to

    I'm not sure what I'm doing wrong. I need this for an assignment.. can someone please tell me what this error means and what I need to do to correct this? Thanks! I'm trying!

    1>.\lab5a.cpp(38) : error C2448: 'Inputdata' : function-style initializer appears to be a function definition


    Code:
    // To take in information of players and scores in a string array
    // to display averages of players ranged to 100 and display averages and below averages
    #include <iostream>
    #include <string>
    #include <iomanip>
    using namespace std;
    
    // declare variables 
    const int ARRAY = 100;
    string name [ARRAY];
    int score [ARRAY];
    int sum = 0;
    int i = 0;
    int totalscores = 0;
    double average;
    
    
    //prototypes
    int Inputdata();
    void DisplayPlayerData();
    int CaculateAverageScore();
    int DisplayBelowAverage();
    
    int main()
    {
        Inputdata();
        DisplayPlayerData();
        CaculateAverageScore();
        DisplayBelowAverage();
    return 0;
    }
    
    
    
    
    int Inputdata(name[i], score[i], sum, totalscores)
    {
     do 
     {
     cout << "Please enter player name: ";
     getline (cin, name[i]);
     cout << "Please Enter Player Score: ";
    cin >> score[i];
    sum = sum + score[i];
    i++;
    totalscores = i;
     }
         while( name[i] != "Q" || i < ARRAY);
    
         return sum, totalscores;
    }
        
    
    void DisplayPlayerData()
    {
        i = totalscores;
        do 
        {
        cout << "You entered: " << name[i], score[i];
        i--;
        }
         while(i > -1);
    
        
    }
    
    int CalculateAverageScore()
    { 
        double average = sum/totalscores;
        cout << "The average score of the players are : ";
    
        return average;
        
    }

  2. #2
    C++まいる!Cをこわせ!
    Join Date
    Oct 2007
    Location
    Inside my computer
    Posts
    24,654
    >> int Inputdata();
    >> int Inputdata(name[i], score[i], sum, totalscores)
    If you have a book handy, you may wish to review the syntax for function prototypes and functions themselves.

    >>return sum, totalscores;
    You cannot return two variables.
    Either use references to pass in variables to store the result it or use a struct.
    Quote Originally Posted by Adak View Post
    io.h certainly IS included in some modern compilers. It is no longer part of the standard for C, but it is nevertheless, included in the very latest Pelles C versions.
    Quote Originally Posted by Salem View Post
    You mean it's included as a crutch to help ancient programmers limp along without them having to relearn too much.

    Outside of your DOS world, your header file is meaningless.

  3. #3
    The larch
    Join Date
    May 2006
    Posts
    3,573
    This is your prototype:

    Code:
    int Inputdata();
    and this is the definition:

    Code:
    int Inputdata(name[i], score[i], sum, totalscores)
    {
    Firstly, they don't match. And secondly, if you want it to have parameters, you must say what the types of the arguments are.
    I might be wrong.

    Thank you, anon. You sure know how to recognize different types of trees from quite a long way away.
    Quoted more than 1000 times (I hope).

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. dllimport function not allowed
    By steve1_rm in forum C++ Programming
    Replies: 5
    Last Post: 03-11-2008, 03:33 AM
  2. doubt in c parser coding
    By akshara.sinha in forum C Programming
    Replies: 4
    Last Post: 12-23-2007, 01:49 PM
  3. Troubleshooting Input Function
    By SiliconHobo in forum C Programming
    Replies: 14
    Last Post: 12-05-2007, 07:18 AM
  4. Brand new to C need favor
    By dontknowc in forum C Programming
    Replies: 5
    Last Post: 09-21-2007, 10:08 AM
  5. c++ linking problem for x11
    By kron in forum Linux Programming
    Replies: 1
    Last Post: 11-19-2004, 10:18 AM