- #1
Lykin
- 4
- 0
I'm attempting to teach myself C++, and I came across this old C++ problem in my closet. It's a ripped page and I'm not sure what book it's from so it has no solution. It's easy, but I seem to have issues with while loops. If someone would explain the logic or show me an example as to how they would do it that would be much appreciated.
The problem:
-Construct a program that computes the square root of a number. Make compare the difference from your first input to your second input, and so on and so forth (for example, if the first number you input is 4, compare the square root of that to the square root of the next number you input). If the difference of the two numbers is greater than 50, terminate the program.
I have something like this:
But that gives me an "expected primary expression before" error and I'm not really sure where to proceed from here anyhow. Any help is appreciated and thanks in advance.
The problem:
-Construct a program that computes the square root of a number. Make compare the difference from your first input to your second input, and so on and so forth (for example, if the first number you input is 4, compare the square root of that to the square root of the next number you input). If the difference of the two numbers is greater than 50, terminate the program.
I have something like this:
Code:
#include<iostream.h>
#include<iomanip.h>
#include<math.h>
double positivePrint (double num, double square);
int main ()
{
double num, square;
positivePrint(double num, double square);
}
double positivePrint (double num, double square)
{
num==1;
while(num>0, num++);
{
square=sqrt(num);
cout << square << endl;
}
}
}
}
But that gives me an "expected primary expression before" error and I'm not really sure where to proceed from here anyhow. Any help is appreciated and thanks in advance.