Just to be clear on what the problem is - you are saying the last value to be printed is 99% and that is not what you want. Presumably you want it to display 100% or to say that it is finished? |
Sorry for not being clear. No, that's not what I want ! I have no problem with any x% printed, I just want it to be erased from the terminal once I move past the loop ! For any loop but the final (j loop), I see the progress... 1%, 55%, 99% whatever and after the loop ends everything gets erased and then again starting from 0, 1 % etc in the next round... and so on.. nice... but after the last round, that is (j = 3 or whatever the final external loop is) that final x% (98 or 99 or 100% ) printed on the screen doesn't get erased !! It stays on the terminal forever... :-( I want it to be gone !
By the way, in my .bash_aliases I have set:
|
alias g+='g++ -Wall -Wextra -Werror -pedantic -std=c++14'
|
So I use "g+" for compiling my codes.
|
if( ((double)i/speed) - (i/speed) == 0)
|
I expect,
(double) i/speed = x.y
and
i/speed = x
, where
x, y
are integers, when
i > speed, x != 0
otherwise
x = 0
. Whenever
i
will be an integral multiple of
speed
, I expect we will have
y = 0
too and hence a match. This is a rough condition but I think it should not interfere with the function
std::flush
. The piece of code that I have provided above, doesn't reproduce my problem.. anyone can check this out by taking a large enough
n
, (
n
much greater than
speed
). But in my real code, I have this kind of loop and after that I call a function... that does something else and prints other stuff on my terminal that doesn't need to be flushed out.
I am not at all an expert in c++ and I am sure you (@TheIdeasMan) have reasons to believe that the precision stuff probably has something to do with the
flush
. But applying my simple numerical logic :) I can't find clues that can connect the two seemingly unrelated issues. Of course I am wrong somewhere....
I will try your suggestion:
Edit: When dealing with doubles, always put digits before and after the decimal point: |