Return Styles: Pseud0ch, Terminal, Valhalla, NES, Geocities, Blue Moon.

Pages: 1-

Python to C++

Name: Anonymous 2009-02-21 7:16

Was wondering if someone could convert this to C++ for me;

a = 1
desiredamount = 64

f = open('double.txt', 'w')
print a
while a < desiredamount:
    a = a * 2
    print a
    value = a
    s = str(value)
    f.write(s)

In case you don't know Python but are willing to give the conversion a shot anyway, Python is pretty self explanatory but two variables, a and desiredamount, while a is less than desiredamount, double it and print the output to "double.txt". I should end up with a log file (double.txt) counting from 1 to 64.
Any help would be greatly appreciated.

Name: Anonymous 2009-02-21 7:20

I AM ONLY USING RUBY FROM NOW ON

Name: Anonymous 2009-02-21 7:25

log file
...

main(){FILE*f=fopen("double.txt","wb");int i;for(i=1;i<64;i*=2)fprintf("%d",i);fclose(f);}

Name: Anonymous 2009-02-21 7:39

Was wondering if someone could hax my anus.

Name: Anonymous 2009-02-21 7:40

>>3
forgot your #include <stdio.h>
but yeah this was trivial

Name: Anonymous 2009-02-21 7:42

   value = a
   s = str(value)
   f.write(s)

Why so many temp variables?you could have just done
f.write(str(a))
or were you trying for ENTERPRISE QUALITY

Name: Anonymous 2009-02-21 7:46

>>3
also it should be fprintf(f,"%d",i); not fprintf("%d",i);

Name: Anonymous 2009-02-21 7:48

>>3
cannot convert `const char*' to `FILE*' for argument `1' to `int fprintf(FILE*, const char*, ...)'

"for(i=1;i<64;i*=2)fprintf("%d",i);"

Name: Anonymous 2009-02-21 8:04

>>8 see >>7

Name: Anonymous 2011-02-04 14:59


Don't change these.
Name: Email:
Entire Thread Thread List