I can not find an error. Nothing derives.

#include <iostream> #include <math.h> using namespace std; int fact(int n) { if (n < 0) { return 0; } return n ? n * fact(n - 1) : 1; } int main() { double sinus = 0; double x = 0, y = 0; double e1 = (pow(10, -4)) / 0.6; //точность вычисления for (x = 0.1; x >= 0.2; x + 0.01) { y = x + 0.74; do { int k = 0; sinus = (pow(-1, k)*(pow(y, 2 * k + 1)) / (fact(2 * k + 1))); ++k; } while (abs(sinus) >= e1); cout << sinus << endl; } return 0; } 

Closed due to the fact that off-topic participants Abyx , aleksandr barakin , VenZell , tutankhamun , Pavel Parshin 2 Mar '16 at 9:25 .

It seems that this question does not correspond to the subject of the site. Those who voted to close it indicated the following reason:

  • “Questions asking for help with debugging (“ why does this code not work? ”) Should include the desired behavior, a specific problem or error, and a minimum code for playing it right in the question . Questions without an explicit description of the problem are useless for other visitors. See How to create minimal, self-sufficient and reproducible example . " - Abyx, aleksandr barakin, VenZell, tutankhamun, Pavel Parshin
If the question can be reformulated according to the rules set out in the certificate , edit it .

  • tried to debug? - Grundy
  • Yes, just did not give anything. - Anna
  • You have a lot of mistakes - an incorrect condition and an increment in a cycle, an incorrect sinus calculation in a while or an exit condition (I still need to remember the expansion in a row :)) - a loop occurs. Try to figure out the code yourself, compare it with the algorithm, then debug it (at least just a sinus output at each iteration of the loop). - Yuriy Orlov
  • Okay I will try. Thank you - Anna

2 answers 2

Your cycle condition is wrong, it is never met. Do this:

 for (x = 0.1; x <= 0.2; x += 0.01) 

In general, you need to view your code with a debugger BEFORE posting a question on the Internet.

  • somehow, highlighting a sign doesn’t help much, it seems to me worth adding in words :) - Grundy
  • @Grundy, you need to add color to the engine, otherwise you have to use words - ixSci
  • @Grundy but in my opinion everything is clear. The HARDWARE certainly should catch a difference. - αλεχολυτ
  • 2
    х += 0.01 , but even with this edit, the problem is Yuriy Orlov
  • @YuriyOrlov, write the full answer? I did not go further there. Write - I will delete my - ixSci

ten! = 1, therefore if(n<=0) {return 1;} correct
2) using pow() for e1 inappropriate, even e1 = 1e-4/0.6 better
3) it is better to make a loop through an integer variable:
for(i = 0; i <=10; i++){ y = 0.75 + 0.01*i;...
4) instead of pow(-1,k) sign factor should be used. Before the do-while loop, put sign = 1; , after the formula, change the sign: sign = -sign;
5) there is no summing up now, so before the do-while loop you should put sinus = 0; in the cycle, replace sinus = assignment by two: calculate the addition to the sine delta =... and adjust the sine: sinus += delta; In the expression under the module use delta instead of sin .

After that you can start debugging