HI EVERYONE IM A NEW MEM AND A BEGINNER IN C++ PROGRAM , HOPE U GUYS CAN HELP ME WITH THIS PROBLEM :
the square root of a number N can be approximated by repeated calculation using the formula : NG =( LG + N/LG)
where ng stands for next guess and lg stands for last guess. Write a function that implements this computation. The first parameter will be a positive real number, the second will be an intial guess of the square root f that number, and the third will be the computed result.The intial guess will be the starting value of lg. The function will compute a value for ng using the formula above. To control the computation, we can use a whie loop. Each time through the loop, the dif between ng and lg is checked to see whether these two guesses are almost identical . If so, the function returns ng as the square root; otherwise, the guess becomes the last guess and the process is repeated . The loop should be repeated until the magnitude of the dif between lg and ng is less than 0.005.....
my code is attached below , i keep getting : error C3861: 'fabs': identifier not found
someone please help !
#include <iostream>
#include <iomanip>
using namespace std ;
void getValues(float&, float& ); //GET VALUES FROM USER FOR N AND LAST-GUESS
void newGuess(float , float , float& ); //CALCULATE FIRST NEXT-GUESS
int main()
{
float n = 0.0;
float lg = 0.0;
float ng = 0.0;
int count = 0;
getValues( n, lg); //GET VALUES FROM USER FOR N AND LAST-GUESS
newGuess( n, lg, ng); //CALCULATE FIRST NEXT-GUESS
count++; //COUNT GUESS
cout << "The " << count << " guess of the square root is " << ng << endl;
while(fabs(lg-ng)>=0.005) //IF LAST-GUESS AND NEXT-GUESS NOT CLOSE ENOUGH
{
lg = ng; //NEXT GUESS BECOMES LAST GUESS
newGuess(n, lg, &ng); //AND PROCESS IS REPEATED
count++;
cout << "The " << count << " guess of the square root is " << ng << endl;
}
cout << endl;
return 0;
}
void getValues(float& n,float& lg);
{
do{
cout<< " PLEASE ENTER THE VALUE OF N"<< ; endl
cin>> n
cout<< " PLEASE ENTER THE VALUE OF LG"<<; endl
cin>> lg>> endl;
}while (lg >= n/2 && n < 0 || lg<0 );
getValues( n, lg); }
void newGuess (float n, float lg, float& ng )
{
ng = (lg/2) + ( n/2lg);
}
the square root of a number N can be approximated by repeated calculation using the formula : NG =( LG + N/LG)
where ng stands for next guess and lg stands for last guess. Write a function that implements this computation. The first parameter will be a positive real number, the second will be an intial guess of the square root f that number, and the third will be the computed result.The intial guess will be the starting value of lg. The function will compute a value for ng using the formula above. To control the computation, we can use a whie loop. Each time through the loop, the dif between ng and lg is checked to see whether these two guesses are almost identical . If so, the function returns ng as the square root; otherwise, the guess becomes the last guess and the process is repeated . The loop should be repeated until the magnitude of the dif between lg and ng is less than 0.005.....
my code is attached below , i keep getting : error C3861: 'fabs': identifier not found
someone please help !
#include <iostream>
#include <iomanip>
using namespace std ;
void getValues(float&, float& ); //GET VALUES FROM USER FOR N AND LAST-GUESS
void newGuess(float , float , float& ); //CALCULATE FIRST NEXT-GUESS
int main()
{
float n = 0.0;
float lg = 0.0;
float ng = 0.0;
int count = 0;
getValues( n, lg); //GET VALUES FROM USER FOR N AND LAST-GUESS
newGuess( n, lg, ng); //CALCULATE FIRST NEXT-GUESS
count++; //COUNT GUESS
cout << "The " << count << " guess of the square root is " << ng << endl;
while(fabs(lg-ng)>=0.005) //IF LAST-GUESS AND NEXT-GUESS NOT CLOSE ENOUGH
{
lg = ng; //NEXT GUESS BECOMES LAST GUESS
newGuess(n, lg, &ng); //AND PROCESS IS REPEATED
count++;
cout << "The " << count << " guess of the square root is " << ng << endl;
}
cout << endl;
return 0;
}
void getValues(float& n,float& lg);
{
do{
cout<< " PLEASE ENTER THE VALUE OF N"<< ; endl
cin>> n
cout<< " PLEASE ENTER THE VALUE OF LG"<<; endl
cin>> lg>> endl;
}while (lg >= n/2 && n < 0 || lg<0 );
getValues( n, lg); }
void newGuess (float n, float lg, float& ng )
{
ng = (lg/2) + ( n/2lg);
}
Comment