Thaksss. Go to the point. When I write in the file am.in.txt 1 (First If) it fulfills a condition (ie, e.1 \ n2 \ n3 \ n4 \ n5 \ n6 \ n7 \ n8 \ n9 writes to the file am.out.txt), and when I write 3 (Third If) it does nothing. I could check something with the condition and wrote in the if-e: cout << "shit" << endl; he doesn't even do that (at that time I had a system ("pause");). If someone found a problem, please help. By the way, I tried to write 4, the same.

ifstream ifn("am.in.txt", ios::in); ofstream ofn("am.out.txt", ios::out); int num; if (!ifn.is_open()) { cout << "Weeelll... Shiiiit" << endl; } else { ifn >> num; cout << num << endl; if (num > 5) { ofn << "nnnope" << endl; } if (num == 1) { ofn << "1\n2\n3\n4\n5\n6\n7\n8\n9" << endl; } if (num == 2) { int a = 1, b = 0, c = 0; for (int i = 10; i < 100; i++) { c = pow(a, 2) + pow(b, 2); if (c == i) { ofn << c << endl; } if (b == 10) { b = 0; a++; } b++; } if (num == 3) { int a = 1, b = 0, c = 0, d = 0; for (int i = 100; i < 1000; i++) { c = pow(a, 3) + pow(b, 3) + pow(d, 3); if (c == i) { ofn << c << endl; } if (d == 10) { d = 0; b++; } if (b == 10) { b = 0; a++; } d++; } ofn.close(); } if (num == 4) { int a = 1, b = 0, c = 0, d = 0, e = 0; for (int i = 1000; i < 10000; i++) { c = pow(a, 4) + pow(b, 4) + pow(d, 4) + pow(e, 4); if (c == i) { ofn << c << endl; } if (e == 10) { e = 0; d++; } if (d == 10) { d = 0; b++; } if (b == 10) { b = 0; a++; } e++; } ofn.close(); } } } 
  • one
    If you are given an exhaustive answer, mark it as correct (a daw opposite the selected answer). - Nicolas Chabanovsky

1 answer 1

Well, take a look for yourself - you have the same condition

 if (num == 3) 

is in the body

 if (num == 2) 

Well, and how, if num is 2, can the condition num==3 be true?

By the way, and for 4 the same ...

In my opinion, you missed one closing bracket } , or rather, put it in the wrong place ...