Hello

I'm haveing a problem running my program because i keep getting error C2447: '{' : missing function header (old-style formal list?). Can someone explain to me how to fix this problem? Below is a copy of my program. The program is designed to take three number inputed buy the user and determine which one is the highest.

#include "stdafx.h"
#include "conio.h"
#include <iostream>


using std::cout;
using std::cin;
using std::endl;
using namespace std;

// function maximum definition;
	// x, y and z are parameters

float maximum(float x, float y, float z);
{
	double x;   // assume x is largest
	double y;
	double z;

	if (x > y) && (x > Z) 
		maximum = x
	else
		if (y > x) && (y > z)
			maximum = y
		else
			if (z > x) && (z > y)
				maximum = z

	return maximum;       // max is largest value
	
} // end function maximum

float maximum(float number1, float number2, float number3); // functional prototype

int main()
{
	double number1;
	double number2;
	double number3;
	cout << "Enter three floating-point numbers: ";
	cin >> number1 >> number2 >> number3;

	// number1, number2 and number3 are arguments to 
	// the maximum function call
   cout << "Maximum is: " << number1 << number2 << number3 << endl;

   return 0;  // indicates successful termination


} // end main

Recommended Answers

All 11 Replies

>>float maximum(float x, float y, float z);

drop the semicolon at the end of this line.

With the function maximum() being defined before main() you don't need a function declaration as well. So you can delete the following line:
float maximum(float number1, float number2, float number3); // functional prototype

Okay when i take the (;) off the end of float maximun( float x, float y, float z) I get errors for the x,y,z variables and at the begining of the if then statement. However the function header error goes away. do Have any advice on that. I have listed the errors below.

error C2082: redefinition of formal parameter 'x'
error C2082: redefinition of formal parameter 'y'
error C2082: redefinition of formal parameter 'z'
error C2143: syntax error : missing ';' before '&&'
warning C4390: ';' : empty controlled statement found; is this the intent?

You need to remove re-definition of these variables agian here..remove these lines
double x; // assume x is largest
double y;
double z;

you forgot call to the function from the main......

int main()
{
double number1;
double number2;
double number3;
double max;
cout << "Enter three floating-point numbers: ";
cin >> number1 >> number2 >> number3;

// number1, number2 and number3 are arguments to 
// the maximum function call
max= maximum( x, y, z); //call to the function.....add this line here..


cout << "Maximum is: " <<max<< endl;

return 0; // indicates successful termination


} // end main

But i still have the problem with the if then statment.

change ur if statements like this....

if( (x > y) && (x > Z) )
maximum = x;
else
if ((y > x) && (y > z))
maximum = y;
else
maximum = z;

Thanx for your help i really appreitiate it but i have one more error what does (error C2659: '=' : function as left operand) mean and how can i fix it. it shows up on the (write part of the if then statment)

sorry..I couldn't get you...could you please tell me in which line you have error.

these are all the errors i am getting

if( (x > y) && (x > Z) )
maximum = x; (error C2659: '=' : function as left operand
else)
if ((y > x) && (y > z))
maximum = y; (error C2659: '=' : function as left operand)
else
maximum = z;(error C2659: '=' : function as left operand)
return maximum; // max is largest value(error C2440: 'return' : cannot convert from 'float (__cdecl *)(float,float,float)' to 'float')

try this....here iam posting total code for ur program....

float maximum(float, float, float); // functional prototype
float maximum(float x, float y, float z)
{
float  max_value;
if( (x > y) && (x > Z) )
max_value = x;
else
if ((y > x) && (y > z))
max_value = y;
else
max_value = z;

return max_value; // max is largest value

} // end function maximum

int main()
{
float  number1;
float  number2;
float  number3;
cout << "Enter three floating-point numbers: ";
cin >> number1 >> number2 >> number3;

// number1, number2 and number3 are arguments to 
// the maximum function call
cout << "Maximum is: " << maximum(number1,number2,number3) << endl;

return 0; // indicates successful termination


} // end main

you the Man YHEA!!!!!

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.