| | |
problem with calling a function
Please support our C++ advertiser: Intel Parallel Studio Home
![]() |
•
•
Join Date: Mar 2008
Posts: 2
Reputation:
Solved Threads: 0
I'm trying to create a function that uses loops to determine the roots of an equation using the Newton-Raphson method. I have my Newton function set up to take the input from my main prog, calculate the roots, and then return them back into the main prog. Somewhere along the lines something is going wrong. When I input my negative and positive values, I receive my first line of output "Call Newton<given guess> saves root and returns function" but then the program stops. I'm not sure if this is a problem with my loop, my Newton function, or with my program calling the Newton function. here is my code
Main program
and here is my Newton function
Main program
C++ Syntax (Toggle Plain Text)
#include "head.h" int main(void) { double guess, root; //variables needed for Newton. char choice = 81; // 81 is decimal code for capital Q; 113 is lower case q int enterkey, i; do { cout << "\nmenu displayed: Enter A for 6.a., B for 3., or Q to quit "; cout << "\nFor example, type B for Exercise 3 followed by Enter key "; choice = toupper(getchar( )); enterkey = getchar( ); cout << choice <<":"<< enterkey << endl; switch (choice) // a decision structure to select only one case out of many { case 'A': for(i=1;i<=2;i++) { cout<<"Enter a negative followed by a positive "<<endl; cin>>guess; cout<<"Call Newton(given guess), returns and saves root\n"; cout<<"After Newton the root is "<<Newton(guess)<<endl; }//end for cout<<"After the loop i is "<<i<<endl; break; default: if (choice != 'Q') {cout << "\nIncorrect Choice: Enter (A,B, or Q as valid)\n"; }//endif } // end switch } while (choice != 'Q'); //end do-while cout << " Fini\n"; system("pause"); return 0;
and here is my Newton function
C++ Syntax (Toggle Plain Text)
double guess, xi,root; int i; double Newton(double guess) { for (i=1,10;1;) { xi=guess; (xi)=(xi-(3*pow(xi,2)+2*xi-2)/(6*xi+2)); }//end for root =xi; cout<<"in Newton\n"; return root; }
![]() |
Similar Threads
- calling a function without changing scope (Python)
- realloc malloc and Heap problem. (C++)
- how to pass values to called function (JavaScript / DHTML / AJAX)
- how to call a function from one file to another file (Shell Scripting)
- Forbidden function names in Dev_C++? (C++)
- Decleration and defination Problem (C++)
- C++ Object Pointers Problem (C++)
- Calling function to add HTML to the page (ASP.NET)
- Function call problem (HTML and CSS)
- Still need info on calling a function from bool! (C++)
Other Threads in the C++ Forum
- Previous Thread: problem with template in c++
- Next Thread: Reading .txt file problem ?
| Thread Tools | Search this Thread |
api array based binary bitmap c++ c/c++ calculator char char* class code coding compile console conversion count data database delete deploy desktop developer directshow dll download dynamic dynamiccharacterarray email encryption error file forms fstream function functions game getline givemetehcodez google graph gui homeworkhelp iamthwee ifstream input int java lib linkedlist linker list loop looping loops map math matrix memory multiple news node number numbertoword output pointer problem program programming project python random read recursion recursive reference rpg sorting string strings temperature template templates test text text-file tree unix url variable vector video visual visualstudio win32 windows winsock word wordfrequency wxwidgets





