#include <cstdlib> #include <iostream> #include <Math.h> using namespace std; int main(int argc, char *argv[]) { int i, n; double y_pred = .3, x_pred = .3, y_tek, x_tek, sum = (x_pred/(1 + abs(y_pred))); cout<<"Vvedite natur. n = "; cin>>n; cout<<"x_pred "<<x_pred<<"y_pred "<<y_pred<<"\n"; for(i = 0; i<n; i++){ x_tek = 0.3*x_pred; cout<<"\nx_tek = "<<x_tek<<"\n"; y_tek = x_pred + y_pred; cout<<"\ny_tek = "<<y_tek<<"\n"; sum = sum + (x_tek/(1+abs(y_tek))); x_pred = x_tek; y_pred = y_tek; cout<<"\nsum = "<<sum; } cout<<"\nIskomaya summa = "<<sum; system("pause"); return EXIT_SUCCESS; } 

Does not take the module. If I put variables integer, I do not consider the sum x_tek / (1 + abs (y_tek)) (from 1 to n) ... Help please!

  • What does "does not take the module" mean? What line is executed incorrectly? Can you reproduce the problem on a shorter program? - VladD
  • #include <cstdlib> #include <iostream> #include <Math.h> using namespace std; int main (int argc, char * argv []) {double n; n = abs (n); cout << n << "\ n"; system ("pause"); return EXIT_SUCCESS; } Error: call of overloaded 'abs (double &)' is ambiguous In my program, the string of variable declarations was executed incorrectly (if the variables are double, if I do an int, then all values ​​are zero, because the fractions are initially smaller units.) I do not know what to do. I need to take a module. - Relike

1 answer 1

For float and double - fabs . And also: usually #include <cmath> rather than #include <Math.h> .