kann mir jemand sagen wo hier der wurm drin ist?

  • kann mir jemand sagen wo hier der wurm drin ist?

    ich hab hier n prog des mir ne parabel in ner txt datei ausgibt - aber i-wo hat des n hänger...

    kann nmir jemand vlltl sagen wo das der fehler ist?
    ist in c++ geschrieben

    Quellcode

    1. #include <iostream>
    2. #include <fstream>
    3. using namespace std;
    4. int print (int,int =1);
    5. int hoch (int,int);
    6. int main()
    7. {
    8. int a;
    9. cout<<"X hoch :";
    10. cin>>a;
    11. int schaubild [41][41];
    12. {
    13. int i=0,k,l;
    14. while (i<=20)
    15. {
    16. k=i+21;
    17. l=hoch(i,a);
    18. if (l>41){break;}
    19. else schaubild [l][k]=1;
    20. i+=1;
    21. }
    22. next1:
    23. i=0,k=21,l=0;
    24. int j=20;
    25. while (i<=22)
    26. {
    27. l=hoch(i,a);
    28. if (l>41){break;}
    29. else schaubild [l][k]=1;
    30. k-=1;
    31. i+=1;
    32. }
    33. next2:
    34. i=0; // sinnlos aber compler hängt sonst...
    35. }
    36. {
    37. int i=0,j=0;
    38. while(i<=41)
    39. {
    40. j=0;
    41. while(j<=41)
    42. {
    43. int d;
    44. a=schaubild[i][j];
    45. if (a!=1 && a!=2){a=3;}
    46. print (a,1);
    47. j+=1;
    48. }
    49. print(0,0);
    50. i+=1;
    51. }
    52. }
    53. system("pause");
    54. }
    55. int hoch (int a,int j)
    56. {
    57. int b=1;
    58. int i=0;
    59. while (i<j)
    60. {
    61. b=b*a;
    62. i+=1;
    63. return b;
    64. }
    65. int print (int a,int b)
    66. {
    67. fstream f;
    68. f.open("parabel.txt", ios::out | ios::app | ios::ate);
    69. if (a==1){f<<" #";}
    70. else if (a==2) {f<<" .";}
    71. else if (a==3) {f<<" .";}
    72. if (b==0) {f<<"\n";}
    73. f.close();
    74. }
    Alles anzeigen


    was dabei rauskommt ist ( wenn man als exponent 2 eingibt ) das hier:
    . . . . . . . . . . . . . . . . . . . . . # . . . . . . . . . . . . . . . . . . . .
    . . . . . . . . . . . . . . . . . . . . # . # . . . . . . . . . . . . . . . . . . .
    . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
    . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
    . . . . . . . . . . . . . . . . . . . # . . . # . . . . . . . . . . . . . . . . . .
    . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
    . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
    . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
    . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
    . . . . . . . . . . . . . . . . . . # . . . . . # . . . . . . . . . . . . . . . . #
    # . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
    . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
    . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
    . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
    . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
    . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . # . . . . . . . . .
    . . . . . . . . . . . . . . . . . # . . . . . . . # . . . . . . . . . . . . . . . .
    . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
    . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
    . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
    . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
    . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
    . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . #
    # . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
    . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
    . . . . . . . . . . . . . . . . # . . . . . . . . . # . . . . . . . . . . . . . . .
    . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
    . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
    . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
    . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
    . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
    . . . . . . . . . . . . . . . . . # . . . . . . . . . . . . . . . . . . . # . . . .
    . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . # . . . . . # . # . .
    . . . . . . . . . . . . . . . . . . . . # . # . . . . . . . . . . . . # . . . . . .
    . . . . . . . . . . . . . . . # . . . . . . . . . . . . . . . . . . . . . . . . . .
    . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
    . . . . . . . . . . . . . . . # . . . . . . . . . . . # . . . . . . . . . . . . . .
    . . . . . . . . . . . . . . . . . . . . . . . . . . # . . . . . . . . . . . . . . .
    . . . . . . . . . . . . . . # . . . # . . . . . . . . . . . . . . . . . . . . # . .
    . . . . . . . . . . . . . . . . . . . . . . . . . . . # . # . . . . . . . . . . . .
    . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
    . . . . . . . . . . . # . . . . . . . # . . . . . # . . . . . . . . . . . . . . . .



    thx für antworten

    JeSt
  • Ich hatte gerade nix zu tun und hab mir mal die MÜHE gemacht, mir deinen Code (wenn man das so nennen darf :) ) anzuschauen.
    Oje oh graus

    Aber hier ein paar Verbesserungsvorschläge:
    zuerst mal solltest du dein int-Array initialisieren

    Quellcode

    1. int schaubild [41][41];
    2. for(int i = 0; i < 41; i++){
    3. for(int j = 0; j < 41; j++){
    4. schaubild[i][j] = 0;
    5. }
    6. }

    ansonsten stimmt es
    bei der Ausgabe läufst du etwas zu weit.

    Quellcode

    1. for(int i = 0; i < 41; i++){
    2. for(int j = 0; j < 41; j++){
    3. print(schaubild[i][j], 1);
    4. }
    5. print(0,0);
    6. }


    1. Du solltest deinen Quelltext umbedingt kommentieren
    2. nicht so viele unverständliche Variablennamen verwenden.
    wenn die Variable die Zeile darstellt, dann nenn sie auch zeile
    3. was hast du blos mit all den while-Schleifen vor?
    4. Ich hab deine print-Methode noch geändert
    5. c++ ist OO, vielleicht sollte man sich das doch ein wenig angewöhnen
    6. Konstanten (wie z.B. deine Größe für das Array 41) sollten auch als Konstanten behandelt werden. Weiss gar nicht mehr wie es in c++ funktioniert, aber z.B. bei java

    Quellcode

    1. public final static int GROESSE = 41;

    7. schau dir mal Header-Dateien, Makefiles usw an.
    8. hab ich was vergessen?