Click here to Skip to main content
14,211,690 members
Rate this:
Please Sign up or sign in to vote.
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
Rate this:
Please Sign up or sign in to vote.

Solution 1

Delete the ";" in:

void main ();
{


and

void displayLine ();
{


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


You should delete the "1" in the last "endl" of your program as well
   
v4
Rate this:
Please Sign up or sign in to vote.

Solution 2

Please try it :) :

void displayLine();
 
void main()
{
...
}
 
void displayLine()
{
...
}
   
Rate this:
Please Sign up or sign in to vote.

Solution 3

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.[^]
   
Rate this:
Please Sign up or sign in to vote.

Solution 4

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
   
v3
Rate this:
Please Sign up or sign in to vote.

Solution 5

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.
:)
   
Rate this:
Please Sign up or sign in to vote.

Solution 6

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 :)
   
v2

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



Advertise | Privacy | Cookies | Terms of Service
Web01 | 2.8.190619.2 | Last Updated 5 Mar 2010
Copyright © CodeProject, 1999-2019
All Rights Reserved.
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100