簡體   English   中英

C++ - 當 x = 1.4 和 y = 5.8 時,算法檢查 (x * y + x + y) / (xy) 的值

[英]C++ - algorithm checking the value of (x * y + x + y) / (x-y), when x = 1.4 and y = 5.8

這是代碼。 當我運行它時,什么都沒有出現,只有黑暗。 空白的。 我是初學者,對編碼了解不多。 任何幫助,將不勝感激。

#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;

}

因為您沒有在控制台中打印出任何內容。 要打印結果,請使用std::cout << Wynik; . 而且,您的主 function 中有錯誤,應該是這樣的:

int main() {
    // Your code goes here
}

此外, using namespace std; 被認為是不好的做法,因為它可能會導致與您的其他庫發生沖突,但您會在一本書中閱讀。

#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.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM