At this moment, I am writing a program that solves the real root of the function f(x) = .05x - sin(x) using false position method. I have my code below . It works fine, but i want to make this false position method a function so that my main program will appear short.
I still have 5 methods left and i think that if this method is fixed then all the other remaining methods will also be fixed by similar way.
This is what i want to do in my main program:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17
cout << "What method do you want to use?" << endl;
cout << "Press 4 for false position. "<< endl;
cin >> selection;
if(selection == 4)
First of all, it should be if(selection == 4)
(two equals signs instead of one), since one equal sign is assignment.
Technically, you could take your current code above and pretty much rename main to falseposition (wait, did you want falseposition or flaseposition? You have the latter in your code).
Then stick your current work-in-progress main function in and you should be fine.
You might want to consider returning the calculated value from the function and move the code that prints it to the screen into main, though. (That way, you won't have to duplicate that part of the code in each of your different functions.)