Hey there! About a week ago, I started working with C++, just as a hobby. I started working on a Square Root Calculator, just to use it as a reference for my future C++ projects. :)
However, when some of my friends were wondering that I could implement 'Pi' within my program, I figured I could give it a shot. So I wrote in 4 const doubles about the 4 variations of Pi:
const double pi = 3.1415926535;
const double Pi = 3.1415926535;
const double pI = 3.1415926535;
const double PI = 3.1415926535;
however, because of it counteracting with another error, that only numbers can be typed in, from 0-9, such as this:
for (int i = 0; i < number.length(); ++i) // Loop that goes through all the letters
{
if (number[i] != '.' && number[i] < '0' || '9' < number[i] || number[0] == 'p' && number[1] == 'i') // Does the character have a value under 0 or above 9, a demical or 'Pi'?
{
cout << "\nERROR: " << "'" << number << "'" << " is not a number.\n";
main();
}
if(number[i] == '.')
{
dotsomg++;
}
}
if(number[0] == 'p' && number[1] == 'i')
{
number[i] == 'pi';
}
I know the code is defiantly wrong, but this is what I'm stuck at so far. The old code that I thought would work better would be this:
for (int i = 0; i < number.length(); ++i) // Loop that goes through all the letters
{
if (number[i] != '.' && number[i] < '0' || '9' < number[i] || number[i] == 'pi' || number[i] == 'PI' || number[i] == 'pI' || number[i] == 'Pi') // Does the character have a value under 0 or above 9, a demical or 'Pi'?
{
cout << "\nERROR: " << "'" << number << "'" << " is not a number.\n";
main();
}
if(number[i] == '.')
{
dotsomg++;
}
}
if(number[i] = pi || number[i] == PI || number[i] == Pi || number[i] == pI)
{
number[i] = pi;
}
EDIT: The "number" was only for testing, but I doubt that it is still correct though. =/
However, both codes no not work, and I am stumped. If you guys want me to post the entire code, then np, if not, then I'll try and discuss this more in depth.
I tried to make this post as understanding to the best of my ability, but I do have a slight speech impediment, so forgive me if I don't make sense in some parts...
Take care for now. :)