【发布时间】:2014-01-02 13:04:03
【问题描述】:
#include <iostream>
#include <math.h>
using namespace std;
int main()
{
double a,b,c,d,X,Y;
float x1,x2;
char ans,i;
do
{
cout << "Welcome!" <<endl
<< "To my Simple Machine" <<endl
<<endl
<< "Enter the value of a:" <<endl;
cin >>a;
cout << "Enter the value of b:" <<endl;
cin >>b;
cout << "Enter the value of c:" <<endl;
cin >>c;
d=b*b-4*a*c;
x1=(-1*b+sqrt(b*b-4*a*c))/2*a;
x2=(-1*b-sqrt(b*b-4*a*c))/2*a;
X=-b/2*a;
如果用户将在 a、b、c 上输入一个字符,我想显示错误
if(a==0)
{
cout << "You are now solvin a Linear Eq'n" <<endl;
Y=-c/b;
cout << "The value of Y is:" <<Y<<endl
<<endl
<< "Do you want to repeat?" <<endl
<< "Loading...." <<endl;
}
else if(d==0)
{
cout << "You are now solving a Quadratic Eq'n" <<endl
<< "The value of d is:" <<d<<endl
<< "x1 is:" <<x1<<endl
<< "x2 is:" <<x2<<endl
<<endl
<< "Do you want to repeat?" <<endl
<< "Loading...." <<endl;
}
else if(d>0)
{
cout << "You are now solving a Quadratic Eq'n" <<endl
<< "The value of d is:" <<d<<endl
<< "x1 is:" <<x1<<endl
<< "x2 is:" <<x2<<endl
<<endl
<< "Do you want to repeat?" <<endl
<< "Loading...." <<endl;
}
else if(d<0)
{
cout << "You are now solving a Quadratic Eq'n" <<endl
<< "The value of d is:" <<d<<endl
<< "x1 is:" <<X<<"+"<<sqrt(-d)/2*a<<'i'<<endl
<< "x2 is:" <<X<<"-"<<sqrt(-d)/2*a<<'i'<<endl
<<endl
<< "Do you want to repeat?" <<endl
<< "Loading...." <<endl;
}
cout.setf(ios::fixed);
cout.setf(ios::showpoint);
cout.precision(2);
}while(ans=='y' ||ans=='Y');
cout << "End of Program..." <<endl
<< "Thank You!" <<endl;
cin.get();
cin.get();
return 0;
}
我无法编译它,因为它说 g++.exe 不工作
【问题讨论】:
-
请edit您的问题与您遇到的确切错误。
-
“我无法编译它,因为它说 g++.exe 不工作” - 也许你的 g++ 已损坏?
-
如果您的桌面编译器不工作。暂时尝试在线的。 ideone.com