How to do Square Roots in C++ - WITHOUT "SQRT" Command
K, so this is what we have so far (CompSci class)
#include <iostream.h>
int main()
{
float integer1, integer2, integer3, integer4, integer5, integer6, dividend; //declaration of variablescout<<"Enter first grade: \n";//prompt for first grade
cin>>integer1;//read integer1
cout<<"Enter second grade: \n";//prompt for second grade
cin>>integer2;//read integer2
cout<<"Enter third grade: \n";//prompt for third grade
cin>>integer3;//read integer3
cout<<"Enter fourth grade: \n";//prompt for fourth grade
cin>>integer4;//read integer4
cout<<"Enter fifth grade: \n";//prompt for fifth grade
cin>>integer5;//read integer5
integer6=integer1+integer2+integer3+integer4+integer5;//assignment for sum of all grades
dividend=integer6/5;//divides sum to find average
cout<<"Average grade equals "<<dividend<<endl;//displays average of grades to user.cout<<"Enter lean tissue mass: ";//prompts lean tissue mass.
cin>>integer1;//assigns lean tissue mass.
cout<<"Enter total body weight (pounds): ";//prompts total body weight.
cin>>integer2;//assigns total body weight.
integer3 = (integer1-integer2)/2.2;//solves for value of body fat.
cout<<"Body fat equals "<<integer3<<endl;//displays body fatcout <<"Enter the first side of the right triangle\n";//assign first side
cin >> integer1;//redefine integer1
cout <<"Enter the second side\n";//assign second side
cin >> integer2;//redefine integer2
integer3=(integer1*integer1)+(integer2*integer2);//finds hypotenuse squared
integer3=(integer4*integer4);//finds hypotenuse
cout <<"The hypotenuse of the right triangle is "<<integer4<<endl;return(0);//indicate that the program has ended successfully
}
The first two parts seem to work fine, though the third part seems to display the integer4 from the first part of the program. I know I'm missing something, if anyone can help out that has any experience, I (and my group) would be most appreciative.
**We can't use the SQRT function, as we haven't 'learned' this yet.**