I am looking for help for my c++ project:
#include <iostream>
#include <cmath>
int main() {
double x;
double y;
double z;
std::string variant;
std::cout << "Ievadi X vertibu!" << std::endl;
if (std::cin >> x) {
std::cout << "X - " << x;
std::cout << "Ievadi Y vertibu!" << std::endl;
if (std::cin >> y) {
std::cout << "Y - " << y;
if (x < -10 && y < -5) {
z = (1 / x) + (1 / y);
variant = "PIRMAIS";
}
else if ((-10 <= x && x < 0) && (-5 <= y && y < 0)) {
z = (x - y) / (x + y);
variant = "OTRAIS";
}
else if ((0 <= x && x < 2 * M_PI) && (y >= 0 && y < (M_PI / 2))) {
z = std::sin(x) / std::cos(y);
variant = "TRESHAIS";
}
else {
z = log((pow(x, 2)) + pow(y, 2));
}
}
else {
std::cerr << "Y ievade bija nepareiza";
}
}
std::cout << std::endl;
std::cout << "result: " << z << std::endl;
std::cout << variant;
return 0;
}
The code is almost correct and working, but in the terminal it finds one problem:
expected ‘;’ before ‘if’
Where is my error? I still don’t get it, and I am confused. Can someone help me please? Explain to me where the issue is.
please post the complete error message, it contains the line number and the code where the error is located
cannot reproduce godbolt.org/z/e463vEhx8. Most likely you are compiling different code, did you save the file? Try a clean build?
Can’t replicate godbolt.org/z/Tso3hGzs5. Have you saved your file?
x == std::clamp(x, min, max)
is fashionable for a within-range check.Having just one compiler error message does not make code almost correct and working.
Show 2 more comments