Why i get this result?

Finally debuged my program, but when I compile it with a test data series, always get wrong result a single 0 in proba.txt file.

The code is:

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
//degree distribution with visibility transform

#include <iostream>
#include <stdio.h>
#include <stdlib.h>
#include <fstream>
#include <math.h>
using namespace std;

#define adatszam 3

int fokszam;
int i;
int a,b,c;
float ya,yb,yc;
float data[adatszam];
int k[adatszam];
FILE  *inf, *outf;


int main() {
    inf = fopen("proba.txt","r");
    for (i=0; i<adatszam; i++)
    {
    fscanf(inf,"%d %f", &k[i], &data[i]);
    }
    fclose(inf);
    for (i = 0; i < adatszam; ++i) {
        fokszam = 0;
        a = k[i];
        ya = data[i];
        for (int n = 0; n < adatszam; ++n) {
            if (n==i) continue;
            b = k[n];                        
            yb = data[n];
            int sz = 0;
            if (i>n){
                     for (int a = n+1; a<i; a++) {
                         c = k[a];
                         yc = data[a];
                         if (yc < yb + (ya-yb)*((b-c)/(b-a)))
                            sz += 1;
                         if (sz==(i-n+1))
                            fokszam+=1;
                            }
                     }
            else {
                 for (int a = n-1; a>i; a--) {
                         c = k[a];
                         yc = data[a];
                         if (yc < yb + (ya-yb)*((b-c)/(b-a)))
                            sz += 1;
                         if (sz==(i-n+1))
                            fokszam+=1;
                                   }
                 }
         ofstream myfile ("probagraf.txt");
         if (myfile.is_open())
         {
         myfile << fokszam << '\n';
         }
         myfile.close();
    }
}
    cout << "Elkeszultem a kiertekelessel";
    cin.get();
    return 0;
}


It runs succesfully because i get the line "Elkeszultem a kiertekelessel" (at the end of the program, see in line 65).
If anyone have any idea why I got this obviously wrong result, pls help me out.

P.s.: if u need clarification about what sequence does what just ask!
Duplicate!
Topic archived. No new replies allowed.