简体   繁体   中英

main.cpp|34|error: 'putere' was not declared in this scope| [and also verif_polim (functions)]

Ok soo this is supposed to find the roots of any polynomial function, but i get this error and I don t understand why. The other ones work perfectly. aflare_radacini splits the problem in 2 cases. First one if the x^0*a it s 0 or not. gasire_rad_1 is for the a[0] = 0 and div for a[0].= 0.

#include <iostream>
using namespace std;

void citire(int a[100], int& n)
{
    cin >> n;
    for (int i = n; i >= 0; i--) {
        cin >> a[i];
    }
}
void gasire_rad_1(int nr)
{
    for (int d = 1; d <= nr / 2; d++) {
        if (nr % d == 0) {
            cout << d << " " << -d << " ";
        }
    }
}
void div(int nr, int n, int a[100])
{
    for (int d = 1; d <= 0; d++) {
        if (nr % d == 0) {
            if (verif_polim(d, n, a) == 0) {
                cout << d << " ";
            }
            if (verif_polim(-d, n, a) == 0) {
                cout << -d << " ";
            }
        }
    }
}
int verif_polim(int x, int n, int a[100])
{
    int s = a[0];
    for (int i = 1; i <= n; i++) {
        int p = putere(x, i);
        s += p * a[i];
    }
}
int putere(int x, int val_putere)
{
    int i = 1, b = 1;
    while (i <= val_putere) {
        b *= x;
        i++;
    }
    return b;
}
void aflare_radacini(int a[100], int n)
{
    if (a[0] == 0) {
        int i = 1;
        while (a[i] == 0) {
            i++;
        }
        cout << 0 << " ";
        if (a[i] < 0) {
            a[i] *= -1;
        }
        gasire_rad_1(a[i]);
    }
    else {
        div(a[0], n, a);
    }
}

int a[100], n;
int main()
{
    citire(a, n);
    aflare_radacini(a, n);
    return 0;
}

You need to declare the functions before you can call them so place the putere function first and the verif_polim function second in your program.

Also note: According to the declaration verif_polim is supposed to return an int - but it doesn't return anything so your program will have undefined behavior .

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM