I've been racking my brain on this for hours. The goal of the program is to estimate the value of pi using three different formulas. My arithmetic is fine, I've tested it, and if it is wrong, I can correct that easy. The problem is that my if statements don't seem to be working for me. The program will run with an input file. The file would contain a letter (a, b, or c) and then a number to decide how many terms to use. I have my if statements as if a; if b; and if c.. However every letter i use seems to be recognized as an 'a' . so it's not even using my if statements for b and c. any ideas? I think it's a formatting issue.
#include <iostream>
#include <iomanip>
#include <cmath>
using namespace std;
int main ()
{
double da = 1; //denominator for Aa
double db = 1; //denominator for Bb
double dc = 2; //denominator for Cc
double terms; //# of terms to sum in the series
double sum = 0; //sum of the terms of the series
char series; //char value to determine which series to use
double pi; //estimation of pi
double neg = -1; //determine whether value is negative or positive in series
double n = -1; //numerator value
cout << endl;
cout << setw(9) << left << "SERIES" << setw(7) << right << "# TERMS" <<
setw(15) << "ESTIMATE" << endl;
cin >> series;
while (!cin.eof())
{
cin >> terms;
bool A,a = true;
if (series == 'A' || 'a')
{
for (int i=0; i<terms; i++)
{
n = n*neg;
sum = sum+(n/da);
da = da+2;
}
pi = sum*4;
cout << fixed << showpoint << setprecision(10);
cout << pi << endl;
}
else //series != a or A
{
bool B,b = true;
if (series == 'B' || 'b')
{
for (int i=1; i<=terms; i++)
{
n = n*neg;
db = db*db;
sum = sum+(n/db);
db = sqrt(db);
db = db+1;
}
pi = sqrt(12*sum);
cout << pi << endl;
}
else //series != b or B
{
bool c,C = true;
if (series == 'C' || 'c')
{
for (int i=0; i<terms; i++)
{
n = n*neg;
dc = dc*dc;
sum = sum+(n/dc);
dc = sqrt(dc);
dc = dc+2;
}
pi = sqrt(sum*24);
cout << pi << endl;
}
}
}
cin >> series;
}
}