local function definitions are illegal...help plz

Ok so I have been working on the following program for quit some time now (my eyes burn :p). I feel i have most of the code in place, as it should be, but when I compile I am getting "error C2601: 'FloatSum' : local function definitions are illegal"

I can't seem to figure out exactly what I am missing. The program is supposed to create a menu giving users 5 options, and I need to get it to loop. I had this working so that it would compile but it was not looping properly and now I am worse off then where i was. Any suggestions would great, thx!

#include <iostream>
#include <iomanip>
using namespace std;

void Swap(float&, float&);
float FloatSum (float, float, float);
float FloatProduct (float, float, float);
float FloatAverage (float, float, float);
void FloatSort (float&, float&, float&);

int main() {

float a, b, c;
int option;

cout << "Options:\n" << "----- \n" << "1. Sum \n"
<< "2. Product \n" << "3. Average \n"
<< "4. Sort \n" << "5. Exit \n";
cout << "Enter your choice: ";

cin >> option;
cout << endl;

while(option != 0){

switch(option)
{
case 1:
cout << "Enter 3 float values: ";
cin >> a >> b >> c;
FloatSum(a, b, c);
cout << "The sum of the numbers = " << FloatSum(a, b, c) << endl;

case 2:
cout << "Enter 3 float values: ";
cin >> a >> b >> c;
cout << "The product of the numbers = " << FloatProduct(a, b, c) <<endl;

case 3:
cout << "Enter 3 float values: ";
cin >> a >> b >> c;
cout<<"The average of the numbers = "<< FloatAverage(a ,b ,c) <<endl;

case 4:
cout << "Enter 3 float values: ";
cin >> a >> b >> c;

case 5: (a <0 ||b <0 || c<0);
cout<<"Error!! Please enter positive integers only";
cout<<"Enter 3 float values: ";
cin >> a >> b >> c;

FloatSort(a, b ,c);
cout << "The numbers in order:"<< c <<" "<< b <<" "<< a <<endl;
}
if(option != 5) {

cout << "DONE!" << endl;
}


cout << endl;
cout << "Options:\n" << "----- \n" << "1. Sum \n"
<< "2. Product \n" << "3. Average \n"
<< "4. Sort \n" << "5. Exit \n";
cout << "Enter your choice: ";
cin >> option;
cout << endl;

return 0;
}

//function definitions:

//*****************************************************************
float FloatSum (float a1,float b2,float c3){

float sum;
sum = a1 + b2 + c3;

return sum;
}

float FloatProduct( float a, float b, float c){

float product;
product = a * b * c;

return product;
}

float FloatAverage( float a, float b, float c){

float average;
average = (FloatSum(a, b, c)) / 3;

return average;
}

void FloatSort( float& a, float& b, float& c){

Swap(a,b);
Swap(b,c);
Swap(a,c);
}

void Swap(float& a, float& b){
float temp;
if (b > a){
temp=a;
a=b;
b=temp;
}
}
[3710 byte] By [keithb1984] at [2007-11-20 11:57:38]
# 1 Re: local function definitions are illegal...help plz
you are missing a "}" that closes your while loop

and also between the cases in the switch, you need to have "break;" to separate the cases.
bovinedragon at 2007-11-11 4:01:58 >
# 2 Re: local function definitions are illegal...help plz
okay so I tried your suggestion, and I fixed a few small issues with quotation marks but my code still won't compile properly. It appears to be something wrong with the way I am using my user defined function. Here is my code again:

#include <iostream>
#include <iomanip>
using namespace std;

void Swap(float&, float&);
float FloatSum (float, float, float);
float FloatProduct (float, float, float);
float FloatAverage (float, float, float);
void FloatSort (float&, float&, float&);

void main(){

float a, b, c;
int option;

cout<<endl;
cout << "Options:\n"; //output statements for menu choices
cout << "------\n";
cout << "1. Sum\n";
cout << "2. Product\n";
cout << "3. Average\n";
cout << "4. Sort\n";
cout << "5. Exit\n";
cout << "Enter your choice: ";
cin >> option;
cout << endl;

while(option != 0){

switch(option)
{
case 1:
cout << "Enter 3 float values: ";
cin >> a >> b >> c;
FloatSum(a, b, c);
cout << "The sum of the numbers = " << FloatSum(a, b, c) << endl;

case 2:
cout << "Enter 3 float values: ";
cin >> a >> b >> c;
cout << "The product of the numbers = " << FloatProduct(a, b, c) <<endl;

case 3:
cout << "Enter 3 float values: ";
cin >> a >> b >> c;
cout<<"The average of the numbers = "<< FloatAverage(a ,b ,c) <<endl;

case 4:
cout << "Enter 3 float values: ";
cin >> a >> b >> c;

case 5: (a <0 ||b <0 || c<0);
cout<<"Error!! Please enter positive integers only";
cout<<"Enter 3 float values: ";
cin >> a >> b >> c;

FloatSort(a, b ,c);
cout << "The numbers in order:"<< c <<" "<< b <<" "<< a <<endl;
}
if(option != 5) {

cout << "DONE!" << endl;
}


cout << endl;
cout << "Options:\n" << "----- \n" << "1. Sum \n";
cout << "2. Product \n" << "3. Average \n";
cout << "4. Sort \n" << "5. Exit \n";
cout << "Enter your choice: ";
cin >> option;
cout << endl;


}

//function definitions:

//*****************************************************************
float FloatSum (float a1,float b2,float c3){

float sum;
sum = a1 + b2 + c3;

return sum;
}

float FloatProduct( float a, float b, float c){

float product;
product = a * b * c;

return product;
}

float FloatAverage( float a, float b, float c){

float average;
average = (FloatSum(a, b, c)) / 3;

return average;
}

void FloatSort( float& a, float& b, float& c){

Swap(a,b);
Swap(b,c);
Swap(a,c);
}

void Swap(float& a, float& b){
float temp;
if (b > a){
temp=a;
a=b;
b=temp;
}
}

Here is there output when I try to compile, by the way I am using Visual C++ 2005:

1>-- Build started: Project: Assignment3_2, Configuration: Debug Win32 --
1>Compiling...
1>Assignment3_2.cpp
1>c:\users\ch0sen\desktop\cosc labs\assignment3_2\assignment3_2\assignment3_2.cpp(87) : error C2601: 'FloatSum' : local function definitions are illegal
1> c:\users\ch0sen\desktop\cosc labs\assignment3_2\assignment3_2\assignment3_2.cpp(18): this line contains a '{' which has not yet been matched
1>c:\users\ch0sen\desktop\cosc labs\assignment3_2\assignment3_2\assignment3_2.cpp(95) : error C2601: 'FloatProduct' : local function definitions are illegal
1> c:\users\ch0sen\desktop\cosc labs\assignment3_2\assignment3_2\assignment3_2.cpp(18): this line contains a '{' which has not yet been matched
1>c:\users\ch0sen\desktop\cosc labs\assignment3_2\assignment3_2\assignment3_2.cpp(103) : error C2601: 'FloatAverage' : local function definitions are illegal
1> c:\users\ch0sen\desktop\cosc labs\assignment3_2\assignment3_2\assignment3_2.cpp(18): this line contains a '{' which has not yet been matched
1>c:\users\ch0sen\desktop\cosc labs\assignment3_2\assignment3_2\assignment3_2.cpp(112) : error C2601: 'FloatSort' : local function definitions are illegal
1> c:\users\ch0sen\desktop\cosc labs\assignment3_2\assignment3_2\assignment3_2.cpp(18): this line contains a '{' which has not yet been matched
1>c:\users\ch0sen\desktop\cosc labs\assignment3_2\assignment3_2\assignment3_2.cpp(120) : error C2601: 'Swap' : local function definitions are illegal
1> c:\users\ch0sen\desktop\cosc labs\assignment3_2\assignment3_2\assignment3_2.cpp(18): this line contains a '{' which has not yet been matched
1>c:\users\ch0sen\desktop\cosc labs\assignment3_2\assignment3_2\assignment3_2.cpp(128) : fatal error C1075: end of file found before the left brace '{' at 'c:\users\ch0sen\desktop\cosc labs\assignment3_2\assignment3_2\assignment3_2.cpp(18)' was matched
1>Build log was saved at "file://c:\Users\ch0sen\Desktop\COSC Labs\Assignment3_2\Assignment3_2\Debug\BuildLog.htm"
1>Assignment3_2 - 6 error(s), 0 warning(s)
========== Build: 0 succeeded, 1 failed, 0 up-to-date, 0 skipped ==========
]

any idea's? thanks again i really appreciate it
keithb1984 at 2007-11-11 4:03:01 >
# 3 Re: local function definitions are illegal...help plz
You are missing a closing bracket '}' at the end of your main function.

Also, according to the C++ standard, the main method should return int, not void.

In case 1, you call FloatSum twice.

Laitinen
laitinen at 2007-11-11 4:03:54 >
# 4 Re: local function definitions are illegal...help plz
If you're writing your code in an IDE (as opposed to a plain text editor) there's almost always a feature for displaying 'matching' brackets. Mismatched brackets is such a common programming mistake that all decent IDEs have some easy means of checking them. Tell us what IDE you use and someone will probably be able to explain how to do it in your IDE.
John E at 2007-11-11 4:05:00 >
# 5 Re: local function definitions are illegal...help plz
Alright so this is a follow up to my own post, I was able to resolve my issues with a little help from the replies i received <-- THANKS GUYS!

Here is my final code:

#include <iostream>
#include <iomanip>
using namespace std;

void Swap(float&, float&);
float FloatSum (float, float, float);
float FloatProduct (float, float, float);
float FloatAverage (float, float, float);
void FloatSort (float&, float&, float&);

int main(){

float a, b, c;
int option;

cout <<endl;
cout << "Options:\n";
cout << "------\n";
cout << "1. Sum \n";
cout << "2. Product \n";
cout << "3. Average \n";
cout << "4. Sort \n";
cout << "5. Exit \n";

cout << "\nEnter your choice:";
cin >> option;


while(option != 5){

cout << "Enter 3 float values: ";
cin >> a >> b >> c;


if(option == 1)
{
FloatSum(a, b, c);
cout << "The sum of the numbers = " << FloatSum(a, b, c) << endl;
}
else if(option == 2)
{
cout << "The product of the numbers = " << FloatProduct(a, b, c) <<endl;
}
else if(option == 3)
{
cout<<"The average of the numbers = "<< FloatAverage(a ,b ,c) <<endl;
}
else if(option == 4)
{
FloatSort(a, b ,c);
cout << "The numbers in order: " << c <<" " << b <<" "<<a<<endl;
}


cout <<endl;
cout << "Options:\n";
cout << "------\n";
cout << "1. Sum \n";
cout << "2. Product \n";
cout << "3. Average \n";
cout << "4. Sort \n";
cout << "5. Exit \n";

cout << "\nEnter your choice:";
cin >> option;


}
cout << "DONE!" <<endl;
return 0;
}

float FloatSum (float a1,float b2,float c3){

float sum;
sum = a1 + b2 + c3;

return sum;
}

float FloatProduct( float a, float b, float c){

float product;
product = a * b * c;

return product;
}

float FloatAverage( float a, float b, float c){

float average;
average = (FloatSum(a, b, c)) / 3;

return average;
}

void FloatSort( float& a, float& b, float& c){

Swap(a,b);
Swap(b,c);
Swap(a,c);
}

void Swap(float& a, float& b){
float temp;
if (b > a){
temp=a;
a=b;
b=temp;
}
}
keithb1984 at 2007-11-11 4:05:59 >
# 6 Re: local function definitions are illegal...help plz
May I suggest using more consistent indentation? It'll make everything easier.
Lindley at 2007-11-11 4:07:00 >
# 7 Re: local function definitions are illegal...help plz
Also, opening and closing brackets placement.
Long time ago with 13 monitor, number of visible lines per screen was really important. That is why most of programmers used following bracket placement:void function() {
body. . .
}Now monitors are much bigger and placement like this:void function()
{
body. . .
}makes opening and closing brackets much easier to locate and match.
Indents in code is also very important; it makes blocks of code much easier to manage.
JohnCz at 2007-11-11 4:08:01 >
# 8 Re: local function definitions are illegal...help plz
Also, opening and closing brackets placement.
Long time ago with 13 monitor, number of visible lines per screen was really important. That is why most of programmers used following bracket placement:void function() {
body. . .
}Now monitors are much bigger and placement like this:void function()
{
body. . .
}makes opening and closing brackets much easier to locate and match.
Indents in code is also very important; it makes blocks of code much easier to manage.

I agree. It seems more and more people are using that crazy first notation. I find that very hard to read easily.

Line up the braces and it's easy to see if one's missing and which one matches what.
GCDEF at 2007-11-11 4:09:07 >