Cześć, muszę napisać program na zaliczenie. Program napisałem i prawidłowo przekazuje on argumenty do tablicy ale problem jest kiedy potrzebuje zsumować argumenty. Coś jest nie tak z ostatnią pętlą i wychodzą kosmiczne wyniki. W jaki sposób mogę prosto zsumować elementy tablicy(argumenty) aby wynik był poprawny?
#include <iostream>
#include <conio.h>
#include <math.h>
#include <array>
using namespace std;
int main()
{
int x, stop;
cout << " ALGORYTM HORNERA " << endl;
cout << " Program wyznacza wartosc funkcji w punkcie 'x' " << endl;
cout << " Stopien wielomianu: ";
cin >> stop;
int aa[10];
int bb[10];
for (int i = 0; i < stop; i++) {
cout << " PODAJ WARTOSC WSPOLCZYNNIKA " << i + 1 << endl;
cin >> aa[i];
}
for (int y = 0; y < stop; y++) {
cout << " Argument:" << y + 1 << "=" << aa[y] << endl;
}
cout << " Punkt 'x' = ";
cin >> x;
int stop2 = stop;
int wynik = 0;
for (int z = 0; z < stop2; z++) {
bb[z] = aa[z] * pow(x, stop - 1);
stop--;
}
for (int yy = 0; yy < stop2; yy++) {
cout << " Argument:" << yy + 1 << "=" << bb[yy] << endl;
}
int length = stop2;
cout << length << endl;
for (int xx = 0; xx < length; xx++) {
wynik = wynik + bb[xx];
}
cout << " Wartosc funkcji w punkcie " << x << " = " << wynik;
getchar();
return 0;
}