does adding 1 in my code doesn't make any change??
Code:
#include<iostream>
using namespace std;
int main()
{
using namespace std;
float a=2e+6;
cout<<a<<endl;
float b=a+1;
cout<<b<<endl;
cout<<b-a<<endl;
return 0;
}
output is a shown in attachment..
if b and a are same then why their subtraction gives 1??
however i have assigned b=a+1.. if it is so then why both are shown same??
Re: does adding 1 in my code doesn't make any change??
Originally Posted by vkash
if b and a are same then why their subtraction gives 1??
There is a difference in what those variables are internally and how you are displaying them. Obviously b and a are not the same internally. If you use the debugger, you would see that the values are different.
Also, what is that stuff at the bottom of the console display ("Process Returned xxx" and the time)? Are you using Visual C++?
Regards,
Paul McKenzie
Last edited by Paul McKenzie; June 17th, 2012 at 10:27 PM.
Re: does adding 1 in my code doesn't make any change??
Originally Posted by laserlight
An approximation of the value in scientific notation was printed. You could try to avoid this by placing:
Code:
cout.precision(7);
before you start printing.
thanks laser light for your cout.precision....
There is a difference in what those variables are internally and how you are displaying them. Obviously b and a are not the same internally. If you use the debugger, you would see that the values are different.
Also, what is that stuff at the bottom of the console display ("Process Returned xxx" and the time)? Are you using Visual C++?
Regards,
Paul McKenzie
errrrrr....
sorry it's not VC++.. recently my windows xp corrupted so i am on linux(no VC++ here) so it's codeblocks..
after all thanks for your answer.thanks for telling me that internally both a and b are not same...
* The Best Reasons to Target Windows 8
Learn some of the best reasons why you should seriously consider bringing your Android mobile development expertise to bear on the Windows 8 platform.