PDA

View Full Version : سوال: خطا عجیب در کامپایل



sajjadrad
شنبه 28 فروردین 1389, 00:02 صبح
سلام دوستان
این برنامه پیدا کردن دو ریشه یه معادله هست...اما نمیدونم چرا موقع کامپایل خطا میده...خطا رو ضمیمه کردم
سورس برنامه:


#include <iostream>
#include <cmath>
void find_stem (int,int,int,int&,float&,float&);
int main ()
{
int a,b,c;
int d=1;
float x1,x2;
cout<<"enter 3 integers number for a,b,c :"<<endl;
cin>>a>>b>>c;
cout<<"your equation is : "<<a<<"x*x+"<<b<<"x+"<<c<<endl;
find_stem(a,b,c,d,x1,x2);
if (d)
cout<<"your equation have two stem : "<<"x1="<<x1<<" and x2="<<x2;
else cout<<"your equation have one stem : "<<"x="<<x1;
return 0;
}
//************************************************** ************************************
void find_stem (int a,int b,int c,int& d,float& x1,float& x2);
{
int delta=(b*b)-(4*a*c);
if ( delta<0 )
{
cout<<"your equation have not stem.";
exit(1);
}
if (delta==0)
{
x1=(-b)/(2*a);
d=0;
}
else
{
float sqrt_delta = sqrt(delta);
x1=(-b+sqrt_delta)/(2*a);
x2=(-b-sqrt_delta)/(2*a);
}
}

tdkhakpur
شنبه 28 فروردین 1389, 00:07 صبح
//************************************************** ************************************
void find_stem (int a,int b,int c,int& d,float& x1,float& x2);
{

داخل کد فوق شما یه سیمی کالن برای تابعتان اضافه گذاشتید

sajjadrad
شنبه 28 فروردین 1389, 08:51 صبح
مرسی دوست عزیز...برنامه رو بصورت زیر اصلاح کردم:

#include <iostream>
#include <cmath>
using namespace std;
void find_stem (int a,int b,int c,int& d,float& x1,float& x2)
{
int delta=(b*b)-(4*a*c);
if ( delta<0 )
{
cout<<"your equation have not stem.";
exit(1);
}
if (delta==0)
{
x1=(-b)/(2*a);
d=0;
}
else
{
float sd = sqrt(delta);
x1=(-b+sd)/(2*a);
x2=(-b-sd)/(2*a);
}
}
int main ()
{
int a,b,c;
int d=1;
float x1,x2;
cout<<"enter 3 integers number for a,b,c :"<<endl;
cin>>a>>b>>c;
cout<<"your equation is : "<<a<<"x*x+"<<b<<"x+"<<c<<endl;
find_stem(a,b,c,d,x1,x2);
if (d)
cout<<"your equation have two stem : "<<"x1="<<x1<<" and x2="<<x2;
else cout<<"your equation have one stem : "<<"x="<<x1;
return 0;
}

ولی بازم تو لاین 19 خطا میده و میگه فراخوانی تابع sqrt مبهمه:متفکر:
والا خودم موندم توش

اینم خطا ها:



1>c:\users\sajjad\documents\visual studio 2008\projects\1\1\codes.cpp(19) : error C2668: 'sqrt' : ambiguous call to overloaded function
1> c:\program files\microsoft visual studio 9.0\vc\include\math.h(581): could be 'long double sqrt(long double)'
1> c:\program files\microsoft visual studio 9.0\vc\include\math.h(533): or 'float sqrt(float)'
1> c:\program files\microsoft visual studio 9.0\vc\include\math.h(128): or 'double sqrt(double)'

Salar Ashgi
شنبه 28 فروردین 1389, 21:05 عصر
ولی بازم تو لاین 19 خطا میده و میگه فراخوانی تابع sqrt مبهمه


کدتون اشکالی نداره و بدرستی اجرا میشه .

عکس کامپایل برنامه شما در ضمیمه !