我的程序产生错误的输出.为什么

My program produces the wrong output. Why?

本文关键字:输出 为什么 错误 程序 我的      更新时间:2023-10-16
#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函数吗?