Reputation: 11
I'm trying to create a recursive method that will display a sequence of squared numbers from one to a specified maximum number, n. The format of the presentation will be to display first, the sequence of odd numbers squared, starting from the largest odd number (<= n) to the smallest odd number (1), then displaying the even numbers squared, starting with the smallest even number (2) to the largest even number (<= n). I am getting an error message that uninitialized local variable 'upperB' is being used. Any ideas?
#include "stdafx.h"
#include <iostream>
#include <iomanip>
#include <math.h>\
using namespace std;
int main()
//Input a,b are constants,lower and upper approximation points as well as
//precision value N
{ double a, b, N, lowerB, upperB;
cout << "Give me a value for a: ";
cin >> a;
cout << "Give me a value for b: ";
cin >> b;
cout << "Give me a precision :";
cin >> N;
cout << " Give me lower and upper approximations: ";
cin >> lowerB, upperB;
cout << "The root is : " <<
RootFinderSMNEW(a, b, lowerB, upperB, N) << endl;
system("pause");
return 0;
}
double f( double x, double a, double b)
{
return sin((a* x) / (1 + x*x))*atan(b*x) + atan(x);
}
double RootFinderSMNEW(double a, double b, double lowerB, double upperB, int N)
{
double f_left = f(lowerB, a, b);
double now = lowerB + N;
double f_right = f(now, a, b);
while (f_left * f_right > 0 && now < lowerB)
{
f_left = f_right;
now += N;
f_right = f(now, a, b);
}
return now - N / 2;
}
Upvotes: 0
Views: 110
Reputation: 15861
You mean
cin >> lowerB >> upperB;
not
cin >> lowerB, upperB;
What you're doing is not putting a value into upperB, so it's not initialized. Which is exactly what the error message says.
Upvotes: 4