468,512 Members | 1,506 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 468,512 developers. It's quick & easy.

problems with printing double(using cout<<)

I've got problem with printing out double type.
int xx=1, yy=1, zz=0, i=46;
float xxx=1, yyy=1, zzz=0;
long double x=1, y=1, z=0;

for(int i = 0;i<r;i++)
{ zz=xx;
zzz=xxx;
z=x;
xxx=xxx+yyy;
xx=xx+yy;
x=x+y;
yyy=zzz;
yy=zz;
y=z;
cout<<i+3<<"---------"<<x<<"----"<<xx<<"----"<<xxx<<"\n"; /*fibonacci*/
}

i use float, int, and double to see what's the cause of the problem.

program prints out this(if (i==46))

3---------2----2----2
4---------3----3----3
5---------5----5----5
6---------8----8----8
7---------13----13----13
8---------21----21----21
9---------34----34----34
10---------55----55----55
11---------89----89----89
12---------144----144----144
13---------233----233----233
14---------377----377----377
15---------610----610----610
16---------987----987----987
17---------1597----1597----1597
18---------2584----2584----2584
19---------4181----4181----4181
20---------6765----6765----6765
21---------10946----10946----10946
22---------17711----17711----17711
23---------28657----28657----28657
24---------46368----46368----46368
25---------75025----75025----75025
26---------121393----121393----121393
27---------196418----196418----196418
28---------317811----317811----317811
29---------514229----514229----514229
30---------832040----832040----832040
31---------1.34627e+006----1346269----1.34627e+006
32---------2.17831e+006----2178309----2.17831e+006
33---------3.52458e+006----3524578----3.52458e+006
34---------5.70289e+006----5702887----5.70289e+006
35---------9.22747e+006----9227465----9.22747e+006
36---------1.49304e+007----14930352----1.49304e+007
37---------2.41578e+007----24157817----2.41578e+007
38---------3.90882e+007----39088169----3.90882e+007
39---------6.3246e+007----63245986----6.3246e+007
40---------1.02334e+008----102334155----1.02334e+008
41---------1.6558e+008----165580141----1.6558e+008
42---------2.67914e+008----267914296----2.67914e+008
43---------4.33494e+008----433494437----4.33494e+008
44---------7.01409e+008----701408733----7.01409e+008
45---------1.1349e+009----1134903170----1.1349e+009
46---------1.83631e+009----1836311903----1.83631e+009

this should be fibonacci noumbers...
and i tjink there is a problem in double printing. sry for my english... i'm stilll learning... && i'm from Poland sry :(
Oct 7 '06 #1
1 3292
Banfa
9,056 Expert Mod 8TB
The reason you have no replies is that from what you have posted the is not any apparent error. In all cases the numbers printed are the same (more or less).
Oct 9 '06 #2

Post your reply

Sign in to post your reply or Sign up for a free account.

Similar topics

5 posts views Thread by toylet | last post: by
4 posts views Thread by He Shiming | last post: by
7 posts views Thread by Don Tucker | last post: by
4 posts views Thread by adamrobillard | last post: by
8 posts views Thread by Taras_96 | last post: by
reply views Thread by NPC403 | last post: by
1 post views Thread by fmendoza | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.