Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/cplusplus/126.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
为什么在这个C++;它给出了两种不同的结果 下面给出了一个C++程序,求出线性方程组中x和y的值。_C++_Validation_Input - Fatal编程技术网

为什么在这个C++;它给出了两种不同的结果 下面给出了一个C++程序,求出线性方程组中x和y的值。

为什么在这个C++;它给出了两种不同的结果 下面给出了一个C++程序,求出线性方程组中x和y的值。,c++,validation,input,C++,Validation,Input,using namespace std; #include<iostream> int main() { int m,n,a,b,c,p,q,r,x,y; cout<<"For the system of equation ax+by=c and px+qy=r,"; cout<<"\nGive the value of a,b,c,p,q and r respectively:"; cin>>a>>b&

using namespace std;
#include<iostream>
int main()
{
    int m,n,a,b,c,p,q,r,x,y;
    cout<<"For the system of equation ax+by=c and px+qy=r,";
    cout<<"\nGive the value of a,b,c,p,q and r respectively:";
    cin>>a>>b>>c>>p>>q>>r;
    m=q-((p*b)/a);
    n=r-((p*c)/a);
    if(q==0)
        cout<<"No solution";
    else
        y=(n/m);
    x=(c-(b*y))/a;
    cout<<"x= "<<x<<" & y= "<<y<<"\n";
    return 0;
}
使用名称空间std;
#包括
int main()
{
int m,n,a,b,c,p,q,r,x,y;
coutb>>c>>p>>q>>r;
m=q-((p*b)/a);
n=r-((p*c)/a);
如果(q==0)

cout您正在使用
int
类型存储变量。在第一种情况下,
a
为3,这导致方程式中的分数被截断,因为
int
无法存储它们

在第二个示例中,
a
为1,因此不会出现分数,程序会计算正确答案

使用
float
double