0
#include <iostream>
using namespace std;


float read_input()
{


float x[5],a, b ,c, d ,e ;
cout<<"enter 5 numbers:"<<endl;
for (int i=0; i<5; i++)
{ 
cin>>x[i];
}
    a=x[0];
    b=x[1];
    c=x[2];
    d=x[3];
    e=x[4];
    cout<<"a="<<a<<endl;
    cout<<"b="<<b<<endl;
    cout<<"c="<<c<<endl;
    cout<<"d="<<d<<endl;
    cout<<"e="<<e<<endl;



}
float calculate_average()
{
        int total=0 ,avg;
        {
        total += float read_input( a,b , c ,d,e );
        avg = total/5 ;
        }
        cout<<avg<<endl;
        return 0;
}

this is my code but i keep getting (error C2062: type 'float' unexpected)
i real dont know what to do :((((

3
Contributors
2
Replies
14
Views
1 Year
Discussion Span
Last Post by deceptikon
0

total += float read_input( a,b , c ,d,e );
Why does this line of code contain the word float?

Also, inside the funciton calculate_average, the following variables do not exist; a, b, c, d, e. So you cannot use them in this function call. That's OK, though, because the function read_input doesn't actually accept any parameters.

Also, your function read_input says it returns a float, but it doesn't return anything.

You have no main function. Maybe your main function is in another source file, but if you were at the level of being able to use more than one source file, you wouldn't be making these mistakes, so I bet you don't have a main function.

Edited by Moschops

1

total += float read_input( a,b , c ,d,e );

The syntax is wrong for this line. First, the float keyword is unnecessary (perhaps you meant it to be a cast?). Second, read_input does not accept any parameters, so the arguments are also not needed. Try this instead:

total += (int)read_input();

Finally, read_input is defined to return a value, but doesn't actually return a value.

On a side note, consistent formatting would make your code easier to read.

Votes + Comments
thank you soo much you've solved my mess ^_^
This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.