它说没有声明啊
  • 板块学术版
  • 楼主Aronmy
  • 当前回复1
  • 已保存回复1
  • 发布时间2022/12/14 20:46
  • 上次更新2023/10/24 07:42:07
查看原帖
它说没有声明啊
820286
Aronmy楼主2022/12/14 20:46

想做一个因式分解的程序,xb,xc是b,c的前缀,正数就是加号。 编译的时候它说xb,xc没有在这个区域声明,可是bfx1和bfx2没问题啊

#include <iostream>
#include <math.h>
#include <string>
using namespace std;
int main(){
	int a,b,c;
	int i;
	cout<<"Please input the number of integral forms:   ";cin>>i;
	for(int x=0;x<i;++x){
		cout<<"The coefficient of first term:   ";cin>>a;
		cout<<"The coefficient of second term:   ";cin>>b;
		cout<<"The constant term:   ";cin>>c;
		int delta=b*b+4*a*c;
		if(delta<0){
			cout<<"Couldn't be factorization"<<endl;
			continue;
		string xb="";
		if(b>=0)
		xb="+";
		string xc="";
		if(c>=0)
		xc="+";
		}
		if(delta==0){
			cout<<a<<"x2"<< xb <<b<<"x"<< xc <<c<<" = (x"<< xb <<(b/2)<<")2";
		}
		float d=sqrt(delta);int d1=sqrt(delta);
		if(d1-d!=0){
			cout<<"Couldn't be factorization"<<endl;
			continue;
		}
		int x1=(-b+d)/(2*a),x2=(-b-d)/(2*a);
		string bfx1="";
		if(x1>=0)
		bfx1="+";
		string bfx2="";
		if(c>=0)
		bfx1="+";
		cout<<a<<"x2"<< xb <<b<<"x"<< xc <<c<<" = (x"<<bfx1<<x1<<")(x"<<bfx2<<x2<<")"
	}
	return 0;
}
2022/12/14 20:46
加载中...