[英]C++ - algorithm checking the value of (x * y + x + y) / (x-y), when x = 1.4 and y = 5.8
This is the code.这是代码。 When I run it, nothing appears, just darkness.
当我运行它时,什么都没有出现,只有黑暗。 Blank.
空白的。 I'm a beginner, and I don't really know too much about coding.
我是初学者,对编码了解不多。 Any help would be appreciated.
任何帮助,将不胜感激。
#include <iostream>
using namespace std;
int main()
float x;
float y;
float Wynik;
x = 1.4;
y = 5.8;
Wynik = (x * y + x + y) / (x-y);
return 0;
} }
Because you aren't printing out anything in your console.因为您没有在控制台中打印出任何内容。 To print your results, use
std::cout << Wynik;
要打印结果,请使用
std::cout << Wynik;
. . And also, you have an error in your main function, it's supposed to be like this:
而且,您的主 function 中有错误,应该是这样的:
int main() {
// Your code goes here
}
Also, using namespace std;
此外,
using namespace std;
is considered bad practice since it can lead to conflicts with your other libraries, but you'll read that in a book.被认为是不好的做法,因为它可能会导致与您的其他库发生冲突,但您会在一本书中阅读。
#include <iostream>
using namespace std;
int main() {
float x;
float y;
float Wynik;
x = 1.4;
y = 5.8;
Wynik = (x * y + x + y) / (x-y);
cout << Wynik << endl; // This will print your output
return 0;
}
#include <iostream>
int main()
{
const float x = 1.4;
const float y = 5.8;
std::cout << (x * y + x + y) / (x - y) << std::endl; // This will print your output
return 0;
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.