Click here to Skip to main content
15,906,626 members
Please Sign up or sign in to vote.
3.67/5 (2 votes)
See more:
hello everybody , am having a problem when doing some trainning C++. When i compile my code i get an error saying ; Missing function header(old style formal list ) and another saying void should be preceded by ";", i real can't find a way out please can somebody help me ? this is my code below



//this program demonstrates the use of function 

#include <iostream>


using namespace std;

// function prototype
void displayLine ()

void main ();
{
	// Declare and initialized a Variable 
	float numberInput = 0,0;
	float numberSquared=0,0;
	float numberHalved =0,0;

	//emter input Item
	cout <<" Enter a number : ";
	cin >> numberInput ;

	//calculate the square of the number and the number halved 

	numberSquared = numberInput * numberInput ;
	numberHalved =  numberInput / 2 ;

	// Display the output items
	displayLine ();
	cout <<"Result of Calcutations : " << endl ;
	cout <<"Square of the Number : " << numberSquared << endl;
	cout <<"Half of the Number : " << numberHalved << endl;
	system("pause");
}  //end of main function 

//********* Programmer - defined function definitions *********

void displayLine ();
{
	cout <<" --------------------------- : " << endl1;
} //end of displaying line function
Posted
Updated 4-Mar-10 6:23am
v4

Delete the ";" in:

C#
void main ();
{


and

C#
void displayLine ();
{


and insert it in:
MIDL
// function prototype
void displayLine ();


You should delete the "1" in the last "endl" of your program as well
 
Share this answer
 
v4
Please try it :) :

void displayLine();
 
void main()
{
...
}
 
void displayLine()
{
...
}
 
Share this answer
 
I'll add one point to the correct responses by Nelek and Eugen Podsypalnikov that covered the error messages that you were getting. It should be int main() rather than void main(). For reference see here.[^]
 
Share this answer
 
this time i have tried to correct the code , and look what i get as the error; it says that missing function header (old-style formal list ?)

//this program demonstrates the use of function
#include <iostream>


using namespace std;

// function prototype
void displayLine ();

void main ();
{
	// Declare and initialized a Variable 
	float numberInput = 0,0;
	float numberSquared=0,0;
	float numberHalved =0,0;

	//emter input Item
	cout <<" Enter a number : ";
	cin >> numberInput ;

	//calculate the square of the number and the number halved 

	numberSquared = numberInput * numberInput ;
	numberHalved =  numberInput / 2 ;

	// Display the output items
	displayLine ();
	cout <<"Result of Calcutations : " << endl ;
	cout <<"Square of the Number : " << numberSquared << endl;
	cout <<"Half of the Number : " << numberHalved << endl;
	system("pause");
}  //end of main function 

//********* Programmer - defined function definitions *********

void displayLine ()
{
	cout <<" --------------------------- : " << endl;
} //end of displaying line function
 
Share this answer
 
v3
You didn't fully follow the given suggestion, namely there is still a spurious semicolon in the following line
void main ();

please remove it and try again.

BTW don't add fake answers, modify instead the original post.
:)
 
Share this answer
 
first prob : correct third line

void displayLine();

2nd :
4th line
void main() (should not preceded with the ; at defination)

3rd:
5th, 6th, 7th line value initialization
float numberInput = 0.0f;(not 0,0 like u have done)
float numberSquared=0.0f;
float numberHalved =0.0f;


4th:
18th line
void displayLine ()(should not preceded with the ; at defination)

u must be careful with your basics enjoy :)
 
Share this answer
 
v2

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900