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



LinkBack URL
About LinkBacks



