# Float Function Issues

• 10-29-2007
GCNDoug
Float Function Issues
I'm working on this problem for a project and have come across these errors. I'm guessing I can't use floats with functions like I could integers.... I was also wondering if for my last function there is an easier way to sort the numbers!

error C2601: 'Do_Sum' : local function definitions are illegal
(18): this line contains a '{' which has not yet been matched
(91) : error C2601: 'Do_Profuct' : local function definitions are illegal
(18): this line contains a '{' which has not yet been matched
(102) : error C2601: 'Do_Average' : local function definitions are illegal
(18): this line contains a '{' which has not yet been matched
(112) : error C2601: 'Do_Sort' : local function definitions are illegal
18): this line contains a '{' which has not yet been matched
(154) : fatal error C1075: end of file found before the left brace '{' at

This was the original problem!
o Create a menu that gives the user the following choices:

Options:
----------
1. Sum
2. Product
3. Average
4. Sort
5. Exit

o Input 3 float numbers. The program should include a loop (for more than one choice) and a switch statement (for options). Your program has to use modularization: each option should call a function

Here is my code! Any help would be appreciated!

Code:

```// *************************************** //Doug Miller //Lab 3, Part 3 //Working with numbers; to compute average! //**************************************** #include <iostream> #include <iomanip> using namespace std; float Do_Sum (float, float, float); float Do_Product (float, float, float); float Do_Average (float, float, float); void Do_Sort (float&, float&, float&); int main() {         int option = 0;         float v_1 = 0;         float v_2 = 0;         float v_3 =0;         while (option != 5)         {                        cout << "Options" << endl;                 cout << "-------" << endl;                 cout << "\n\n";                 cout << "1.) Sum" << endl;                 cout << "2.) Product" << endl;                 cout << "3.) Average" << endl;                 cout << "4.) Sort" << endl;                 cout << "5.) Exit" <<endl;                 cout << "\n\n";                 cout << "Please enter your choice: " << endl;                 cin >> option;                 cout << "Please enter three values: " << endl;                 cin >> v_1 >> v_2 >> v_3;                                 switch (option)                 {                         case 1:                                 {                                         cout << "The sum of these numbers is" << Do_Sum (v_1, v_2, v_3);                                         cout << "\n\n";                                         break;                                 }                         case 2:                                 {                                         cout << "The product of these numbers is" << Do_Product (v_1, v_2, v_3);                                         cout << "\n\n";                                         break;                         case 3:                                 {                                         cout << "The average of these numbers is" << Do_Average (v_1, v_2, v_3);                                         cout << "\n\n";                                         break;                                 }                         case 4:                                 {                                         Do_Sort (v_1, v_2, v_3);                                         cout << v_1, v_2, v_3;                                         cout << "\n\n";                                         break;                                 }                         case 5:                                 {                                         option = 5;                                         break;                                 }                         default:                                 {                                         cout << "Please renter option: " << endl;                                         cin >> option;                                 }                 }         }                }//END OF MAIN float Do_Sum (float v_1, float v_2, float v_3) {         float total = 0;         total = (v_1 + v_2 + v_3);         return total; }//END OF DO SUM float Do_Profuct (float v_1, float v_2, float v_3) {         float product = 0;         product = (v_1 * v_2 * v_3);         return product; }//END OF DO PRODUCT float Do_Average (float v_1, float v_2, float v_3) {         float average = 0;         average = ((v_1 + v_2 + v_3) / 3);         return average; }//END OF DO AVERAGE void Do_Sort (float& v_1, float& v_2, float& v_3) {         float temp = 0;         if (v_1 > v_2 && v_1 > v_3)         {                 v_1 = v_1;                 if (v_2 > v_3)                 {                         v_2 = v_2;                         v_3 = v_3;                 }                 else                 {                         temp = v_2;                         v_2 = v_3;                         v_3 = temp;                 }         }         else if (v_2 > v_1 && v_2 > v_3)         {                 temo = v_1                 v_1 = v_2                 if (v_1 > v_3)                 {                         v_2 = v_1;                         v_3 = v_3;                 }                 else                 {                         v_2 = v_3;                         v_3 = temp;                 }         else         {                 v_1 = v_1;                 v_2 = v_2;                 v_3 = v_3;         } }//END OF SORT```
• 10-29-2007
Daved
>> this line contains a '{' which has not yet been matched

I don't think it's that line, but you do have an unmatched brace. Find it and fix it.Then compile again and look at the errors. There is at least one more typo in your function definitions.
• 10-29-2007
swoopy
Code:

```>                        case 2: >                                { >                                        cout << "The product of these numbers is" << Do_Product (v_1, v_2, v_3); >                                        cout << "\n\n"; >                                        break; >                        case 3:```
You're missing at the end of case 2. I think you can omit the braces entirely, since it's within a case.
Code:

```>                temo = v_1 >                v_1 = v_2```
You're missing semicolons here, and temp is misspelled. As for an easier way to sort the numbers, if you can use arrays, you could use the sort() function from the standard library.
• 10-29-2007
abachler
One is not supposed to use braces
Code:

` { }`
inside one's case statements.
• 10-29-2007
Daved
>> One is not supposed to use braces inside one's case statements.
Why not? It is necessary if you declare a variable within the case. If you don't, then the braces don't hurt.
• 10-29-2007
King Mir
Quote:

Originally Posted by abachler
One is not supposed to use braces
Code:

` { }`
inside one's case statements.

Why not? It's helps organize the code. They are optional, but they don't hurt.

Braces can be put anywhere in a function body to separate out a section of code. This has the other effect that all local variables declared within the block are destroyed at the end of the block. If there are no local variables, then the braces serve only as a visual que.