我的程序产生错误的输出.为什么
My program produces the wrong output. Why?
#include "stdafx.h"
#include <iostream>
#include <conio.h>
#include <math.h>
using namespace std;
void main() {
float y;
int x;
cout<<"Jep vleren e x-it:"<<endl;
cin>>x;
if (x>=1)
{
y=(x^3 - 2*x)/(1+x^2);
cout<<y<<endl;
}
if ((x>-1)&&(x<1))
{
y = sqrt(1+x^2);
cout<<y<<endl;
}
if (x<=-1)
{
y=x/(1+x^2);
cout<<y<<endl;
}
_getch();
}
我必须根据x计算y的值。但是有问题 - 当我输入- 3
时,它说0
。为什么?
您正在使用 ^ XOR运算符,请参见MSDN您要使用POW函数吗?
相关文章:
- 为什么我的代码在输出中增加了93天
- 为什么我不能在不创建字符串变量的情况下使用函数的字符串输出
- 为什么rk4.do_step不输出C++中的初始条件
- 为什么在C的循环中使用printf的Rust代码不显示输出,而在C++的循环中显示std::cout
- 为什么我在输出端得到 nan?
- 为什么递归函数的最终输出是 5?
- 为什么我的C++程序的程序集输出充满了 .ascii,没有汇编代码?
- 为什么输出精度没有正确舍入?
- 为什么这个程序的输出不如预期
- 有人可以向我解释为什么控制台输出 0 吗?
- 为什么文件不是由 F 流创建的,或者即使它是输出只是垃圾值?
- 为什么我的 if else 语句不起作用并从数组中输出正确的索引?
- 为什么在这种情况下,bool 类型的输出等于 0?
- 执行此代码时,它不显示任何输出.为什么?
- 使用相同消息重新引发新异常会导致垃圾输出.为什么?
- 我的程序产生错误的输出.为什么
- 怪异的输出:为什么这段代码会给出任何有意义的输出,更不用说这个了
- %n格式说明符程序,在不同的编译器上提供不同的输出.为什么?
- 我的简单类函数中出现意外输出.为什么
- 如果语句不求值为false?程序给出奇怪的输出.为什么