not sure why, nether my while loop or my if else statement is not working on line 29 and 38 getting some sort of logic error from what I can tell on the while loop whether I press y or n still keeps looping eventhough I have yesOrno set condition to yesOrno != 'y'|| yesOrno != 'n' and as far as the if else statement well it is not reading remainder as 0 looks like it not sure y but you put 2.5 works fine but you put 5 doesn't work.
#include <iostream>
#include <iomanip>
#include <cstdlib>
usingnamespace std;
int main()
{
double numberTwo,remainder;
int number, count;
char yesOrno;
char endProgram;
do
{
cout << "Please enter an integer" << endl;
cin >> numberTwo;
number = numberTwo;
remainder = numberTwo - number;
if (number > 2147483647)
{
cout << "Need to enter an integer lower than 2147483647 please
enter another integer \n";
cin >> numberTwo;
number = numberTwo;
remainder = numberTwo - number;
}
elseif (number != 0)
{
cout << remainder << " will be trunicated from the "
<< numberTwo << endl;
cout << "If you wish to continue with this integer type y \n";
cout << "otherwise type in n and we will enter another
integer\n";
cin >> yesOrno;
cout << yesOrno << endl;
while(yesOrno != 'n' || yesOrno != 'y')
{
cout << "Please enter a valid y or n \n";
cin >> yesOrno;
}
}
elseif (yesOrno == 'n')
{
cout << "Please enter an integer" << endl;
cin >> numberTwo;
number = numberTwo;
remainder = numberTwo - number;
}
elseif (yesOrno == 'y')
{
cout << "Your floating point number would be \n";
cout << fixed;
cout << setprecision(10) << number << endl;
cout << endl;
cout << endl;
cout << "Would you like to end program or enter another
integer press y for yes and n for no \n";
cin >> endProgram;
while (endProgram != 'n' || endProgram != 'y')
{
cout << "This is not a valid entry! Please enter y for
yes or n for no \n";
cin >> endProgram;
}
}
elseif (endProgram == 'y')
{
count++;
}
elseif (endProgram == 'n')
{
count = 0;
}
} while (count <= 0 );
system ("pause");
return 0;
}
Because any number bigger than INT_MAX would not fit in number in the first place, so the bits in number will be truncated at 32 and any number would be in fact smaller than INT_MAX.
You're if/else logic is messed up. You can't do an if for a number and do an else or elseif for a string, well you can and it might work, but it's not consistent. Plus, I don't see a default case, the body of else is missing.