Hallo,
ich habe das folgende Programm geschrieben.
Beim Kompilieren wird mir kein Fehler angezeigt.
Beim Ausführen der Exe-Datei kommt das Programm mal zu einem richtigen Ergebniss und mal werden völlig falsche Werte angezeigt, obwohl ich an der EXE-Datei ja nichts geändert habe.
Es wirkt auf mich so als ob manchmal mit leeren Werten gerechnet wird.
Das Problem tritt im letzten Abschnitt auf
"test = ((10*(sqrt((px[j]-x)*(px[j]-x[i])+(py[j]-y[i])*(py[j]-y[i]))))/19);"
test nimmt mal die richtigen Werte an und mal die falschen.
Wie kann das sein ?
Vielen Dank im Voraus schonmal!
Gruß Paul
Alles anzeigen
ich habe das folgende Programm geschrieben.
Beim Kompilieren wird mir kein Fehler angezeigt.
Beim Ausführen der Exe-Datei kommt das Programm mal zu einem richtigen Ergebniss und mal werden völlig falsche Werte angezeigt, obwohl ich an der EXE-Datei ja nichts geändert habe.
Es wirkt auf mich so als ob manchmal mit leeren Werten gerechnet wird.
Das Problem tritt im letzten Abschnitt auf
"test = ((10*(sqrt((px[j]-x)*(px[j]-x[i])+(py[j]-y[i])*(py[j]-y[i]))))/19);"
test nimmt mal die richtigen Werte an und mal die falschen.
Wie kann das sein ?
Vielen Dank im Voraus schonmal!
Gruß Paul
C-Quellcode
- [syntax="cpp"]#include <stdio.h>
- #include <math.h>
- #include <stdlib.h>
- int iAnzauslesen (int &iAnz);
- float auslesen (int &iAnz, int *x, int *y, int *AnzP);
- float rand ( int &iAnz, int &anzL, float *px, float *py, int *x, int *y );
- int main()
- {
- int iAnz, i, anzL;
- int *x, *y, *AnzP;
- float *px, *py, *test;
- iAnzauslesen(iAnz);
- x= new int[iAnz+1];
- y= new int[iAnz+1];
- AnzP= new int[iAnz+1];
- test= new float[iAnz+1];
- auslesen (iAnz, x, y, AnzP);
- anzL = 1; /*for (anzL=1;100;anzL++)*/
- px= new float[anzL+1];
- py= new float[anzL+1];
- rand (iAnz, anzL, px, py, x, y);
- }
- int iAnzauslesen (int &iAnz){
- FILE *datei ;
- datei = fopen("Koordinaten.dat","r") ;
- fscanf (datei, "%d",&iAnz) ;
- };
- float auslesen (int &iAnz, int *x, int *y, int *AnzP){
- FILE *datei ;
- datei = fopen("Koordinaten.dat","r") ;
- int i, a, b, c, fail;
- fscanf(datei,"%d", &fail) ;
- for(i=1;i<=iAnz;i++)
- {
- fscanf(datei,"%d %d %d",&a,&b,&c);
- AnzP[i]=a;
- x[i]=b;
- y[i]=c;
- }
- };
- float rand ( int &iAnz, int &anzL, float *px, float *py, int *x, int *y ){
- int i, j;
- float test;
- for (i=1;i<=iAnz;i++)
- {
- for (j=1;j<=anzL;j++)
- {
- printf("%d\n",j);
- px[j]=(rand()%150000) / 150 + 1.0;
- py[j]=(rand()%150000) / 150 + 1.0;
- printf("%2.2f %2.2f\n", px[j], py[j]);
- }
- printf("%d\n",i);
- printf("%d %d\n", x[i], y[i]);
- test = ((10*(sqrt((px[j]-x[i])*(px[j]-x[i])+(py[j]-y[i])*(py[j]-y[i]))))/19);
- printf("%f\n", test);
- }
- };[/syntax]