1 Attachment(s)
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??
Quote:
Originally Posted by vkash
if it is so then why both are shown same?
An approximation of the value in scientific notation was printed. You could try to avoid this by placing:
before you start printing.
Re: does adding 1 in my code doesn't make any change??
Quote:
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
Re: does adding 1 in my code doesn't make any change??
Quote:
Originally Posted by
laserlight
An approximation of the value in scientific notation was printed. You could try to avoid this by placing:
before you start printing.
thanks laser light for your cout.precision....
Quote:
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... :)