//degree distribution with visibility transform
#include <iostream>
#include <stdio.h>
#include <stdlib.h>
#include <fstream>
#include <math.h>
usingnamespace 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!
Would you care to share the results of your debugging? If you already debugged it, then you should have identified the problem already.
I just have a couple of words of advice. The bracket alignment throughout is inconsistent and very difficult to read. Secondly, I see you are using some C++ headers but still writing this as if it were a C program. I find it odd that you are using fscanf to read the input file but using C++ file stream to write to the output file. Why would you want to do that?
I don't understand the problem that you are describing. proba.txt is the input file, correct? What is the content of that file prior to running the program? Are you saying that the fscanf is not reading the input file correctly? In other words, 0 is being read even though the file contains something else? Did you check inf in the debugger to verify that it is not 0? In other words, did the file actually exist and was it opened properly?