CodeBlocks C ++ Bug [英] CodeBlocks C++ Bug
本文介绍了CodeBlocks C ++ Bug的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我在做C ++(CodeBlocks),但我发现一个奇怪的问题。我把我的代码发送给我的朋友(他在DevC ++测试),它的工作。
我试过这两个代码:
I was doing something in C++ (CodeBlocks), but I found a weird problem. I sent my code to my friend (he tested it in DevC++) and it worked. I tried these two codes:
#include <iostream>
#include <math.h>
using namespace std;
int main() //this function works
{
if (pow(3, 2) + pow(4, 2) == pow(5, 2)) {
cout << "Works" << endl;
} else { cout << "Nope" << endl; }
}
但是我改变了main函数, t work):
But, then I changed the main function like this (and it didn't work):
int main() //this function doesn't work
{
int t1 = 3, t2 = 4, t3 = 5;
if (pow(t1, 2) + pow(t2, 2) == pow(t3, 2)) {
cout << "Works" << endl;
} else { cout << "Doesn't work" << endl; }
}
任何人都知道有什么问题?
Anyone knows what's the problem ?
推荐答案
问题是,math.h不工作,所以我必须使用cmath。第二,不是整数,而是浮点数或双精度。
The problem is that the math.h doesn't work, so I have to use cmath. Second, not int, but float or double.
代码:
#include <iostream>
#include <cmath>
using namespace std;
int main()
{
float t1 = 3, t2 = 4, t3 = 5;
if (pow(t1, 2) + pow(t2, 2) == pow(t3, 2)) {
cout << "PT" << endl;
}
else {
cout << pow(t1, 2) + pow(t2, 2) << endl;
cout << pow(t3, 2) << endl;
}
}
这篇关于CodeBlocks C ++ Bug的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文