#include <iostream>
#include <stdlib.h> // C++ programs should include <cstdlib>
usingnamespace std;
int main()
{
system("chcp 1251");
int x;
cout << "Âúâåäè x: "; cin >> x;
if (x <= 0)
{
x = 4; // is this "0 when x <= 0"?
cout <<"x: " << x <<endl; // we don't want x, we want f(x)
}
else // this does "when input > 0"
{
x = x; // this does nothing
cout <<"x: " << x <<endl;
}
if (x > 1) // this is a separate IF
{ // this happens when user input was <= 0 or > 1
x = x^4; // the ^ is not exponent in C++. Write x*x*x*x or use pow()
cout <<"1x: " << x << endl;
}
}
You should compute value of f(x) from input. You are using x for both result and input. It is better to have separate variables for them.
You should use if .. else if .. else .., not if .. else .. and if ..
You repeat the cout <<"x: " << x <<endl; three times (although third differs).
Store result of ifs into variable and have the output once, after all ifs.
In all of 5 posts OP has barely made the effort to ask a coherent question. He’s not trying because he doesn’t care and thinks he can get people online to do his very simple homeworks for him.