I know that you can set the precision in the cout statement but can you set it for the cin statement. the reason i ask this is i am comparing the fraction part of a double in several if statements but as i step through the program it skips all conditons. i added a watch and it seems the number is just above what i am checking for. i am only doing something if the frac part is .3 or above and this is just a test program to see if it works
example:
have the fraction part when computed using modf is .300003
i am trying to see if the frac part = .3 but when run the if statement is ignored.
Referring to the code you posted above, replace lines 23-40 with this:
1 2 3 4 5 6 7
switch ((int)((fracpt + 0.05) * 10)) {
case 3: fracpt = .0; break;
case 4: fracpt = .1; break;
case 5: fracpt = .0; break;
}
total=intpt+1+fracpt;
cout<<total<<"\n";
The idea is that it multiplies the floating point number by 10, pushing the first decimal into the one's position, then converts it to an int, chopping off any remaining decimals. Then it switches on that single digit. Remove the +0.05 if you don't want to round it.