help c++

Good evening everyone
is there anyone who can help me correct the errors of this program.

#include <stdio.h>
#include <math.h>
#include <stdlib.h>
#include <time.h>
#include <iostream>

using namespace std;

using value_type = int;

struct state {
value_type n;
value_type x;
value_type y;

bool domR() const { return (n/2)% 2 == 0; }

bool R() const { return (n == x * x - y * y) && 0 <= y && y <= x; }
};

bool oracle (state const& s) { return (! s.domR()) || s.R() ; }

//je veux réutiliser du code entre les fonctions p1, p2 et p3
value_type set_x(state & s) {
s.x = 0;
while (r < s.n) {
r += 2*s.x+1;
++s.x;
}
return r;
}

set_y(state & s, value_type & r) {
//pas besoin d'entourer un while (condition) par un if(condition), car while teste la condition.
while (r > s.n) {
r -= 2*s.y +1;
++s.y;
}
return r;
}

state p1(value_type n) {
state s {n, 0, 0};
set_x(s);
}

state p2(random_value_type n) {
state s {n, 0, 0};
auto r = set_x(s);
set_y(s, r);
return s;
}

state p3(random_value_type n) {
state s {n, 0, 0};
auto r = set_x(s);

while (r > s.n) {
const auto rsave = r;
r = set_y(s, r);
if (r < s.n) {
s.r = rsave + 2*s.x+1;
++s.x;
}
}
return s;
}

int randomgeneration(int n) {
const auto partSize = 1 + (n == RAND_MAX ? 0 : (RAND_MAX - n) / (n + 1));
const auto maxUsefull = partSize * n + (partSize - 1);

int draw;

do {
draw = rand();
} while (draw > maxUsefull);

return draw / partSize;
}

int main() {
auto const testdatasize = 4000;
// compteurs qui s'incrémente chaque fois que les résultats fourni par le programme satisfait la condition qui est exprimée dans le procedure bool R(N=x2-y2)et (0<=y<x)
std::array<int, 3> counters;

for(int testindex=1; testindex <= testdatasize; ++testindex) {
// pas de déclaration sans initialiseur, il faut définir une variable quand on sait que mettre dedans.

// inutile de créer un inits intermédiaire juste pour stocker un n sans le x et le y correspondant.
auto const n = randomgeneration(10000);
std::cout << "n : " << n << '\t';

if (oracle(p1(n))) ++counters[0];
printf("counter p1 : " << counters[0] << '\t';

if (oracle(p2(n))) ++counters[1];
printf("counter p2 : " << counters[1] << '\t';

if (oracle(p3(n))) ++counters[2];
printf("counter p3 : " << counters[2] << '\t';
}

std::cout << "reliability of p1 : " << (counters[0] / static_cast<double>(testdatasize)) << std::endl;
std::cout << "reliability of p2 : " << (counters[1] / static_cast<double>(testdatasize)) << std::endl;
std::cout << "reliability of p3 : " << (counters[2] / static_cast<double>(testdatasize)) << std::endl;
}
What errors ?
Compile errors, crash, wrong output, no output....?
Using code tags would make this easier to read.
Here's how > http://www.cplusplus.com/articles/jEywvCM9/
Topic archived. No new replies allowed.