Witajcie, jestem kompletnie zielony w programowaniu. Dopiero miałem drugie zajęcia. Napisałem program, wszystko według mnie wygląda okej jednak nie liczy funkcji dla x>10. Może ktoś mi powie gdzie jest błąd? Będę bardzo wdzięczny za pomoc.
#include <iostream>
#include <math.h>
using namespace std;
int main()
{
float i, N, S, alfa, P, a, b, Pi, y, x0, h, k, x;
cout << "podaj liczbe N= ";
cin >> N;
S = 0;
for (i = 1; i <= N; i++)
{
S = S + (i + 1.0) / (2 * i * i + 1);
}
cout << "S=" << S << endl;
cout << "Podaj dlugosc pierwszego boku: ";
cin >> a;
cout << "Podaj dlugosc drugiego boku: ";
cin >> b;
cout << "Podaj kat w stopniach pomiedzy tymi bokami: ";
cin >> alfa;
alfa = alfa * (M_PI / 180);
P = 0.5 * a * b * alfa;
cout << "P=" << P << endl;
cout << "Podaj x0= ";
cin >> x0;
cout << "Podaj h= ";
cin >> h;
cout << "Podaj k= ";
cin >> k;
for (i = 0; i <= k; i++)
{
x = x0 + i * h;
if (x >= -10 and x <= 10) {
y = 0.75 * x * x + 1;
cout << "funkcja y=" << y << " "
<< "dla x= " << x << endl;
{
if (x > 10) {
y = 0.5 * x;
cout << "funkcja y=" << y << " "
<< "dla x= " << x << endl;
{
if (x < -10) {
y = cos(x);
cout << "funkcja y=" << y << " "
<< "dla x= " << x << endl;
}
}
}
}
}
}
return 0;
}