You are not logged in.

  • Login

1

Wednesday, December 13th 2006, 7:07pm

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

C Quellcode

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


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

Quoted

. . . . . . . . . . . . . . . . . . . . . # . . . . . . . . . . . . . . . . . . . .
. . . . . . . . . . . . . . . . . . . . # . # . . . . . . . . . . . . . . . . . . .
. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
. . . . . . . . . . . . . . . . . . . # . . . # . . . . . . . . . . . . . . . . . .
. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
. . . . . . . . . . . . . . . . . . # . . . . . # . . . . . . . . . . . . . . . . #
# . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . # . . . . . . . . .
. . . . . . . . . . . . . . . . . # . . . . . . . # . . . . . . . . . . . . . . . .
. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . #
# . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
. . . . . . . . . . . . . . . . # . . . . . . . . . # . . . . . . . . . . . . . . .
. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
. . . . . . . . . . . . . . . . . # . . . . . . . . . . . . . . . . . . . # . . . .
. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . # . . . . . # . # . .
. . . . . . . . . . . . . . . . . . . . # . # . . . . . . . . . . . . # . . . . . .
. . . . . . . . . . . . . . . # . . . . . . . . . . . . . . . . . . . . . . . . . .
. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
. . . . . . . . . . . . . . . # . . . . . . . . . . . # . . . . . . . . . . . . . .
. . . . . . . . . . . . . . . . . . . . . . . . . . # . . . . . . . . . . . . . . .
. . . . . . . . . . . . . . # . . . # . . . . . . . . . . . . . . . . . . . . # . .
. . . . . . . . . . . . . . . . . . . . . . . . . . . # . # . . . . . . . . . . . .
. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
. . . . . . . . . . . # . . . . . . . # . . . . . # . . . . . . . . . . . . . . . .



thx für antworten

JeSt

2

Wednesday, December 13th 2006, 11:38pm

Wenn du deinen Code kommentieren würdest, würden wir uns alle leichter tun das zu verstehen ... :shock:

3

Thursday, December 14th 2006, 1:26pm

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

C Quellcode

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

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

C Quellcode

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


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

Java Quellcode

1
public final static int GROESSE = 41;

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

4

Thursday, December 14th 2006, 5:52pm

Konstanten in C++:

C Quellcode

1
const int GROESSE = 41;


oder

C Quellcode

1
2
3
4
enum
{
  GROESSE = 41;
};

Similar threads

Social bookmarks