Y
yansong1990
Uhm..it's my 1st time using this fuction...could someone provide
anexample for me please? thanks
anexample for me please? thanks
oh yes one more thing >.< how do i use the sqrt function?
#include <iostream>
#include <cstdlib>
#include <math.h>
using namespace std;
int main()
{
float weight;
cout<<"Enter parcel weight ";
cin>>weight;
if (weight <= 2)
{
cout<<"Cost is $3.25"
<<endl;
goto end;
}
else
{
weight = weight - 2;
ceil(weight);
As for the sqrt...
#include <iostream>
#include <math.h>
#include <cstdlib>
using namespace std;
int main()
{
int number, test;
float squareroot;
cout<<"Input number: ";
cin>>number;
test = 2;
squareroot = sqrt(number);
I will get this error-
1>.\assg3q6.cpp(20) : error C2668: 'sqrt' : ambiguous call to
overloaded function
1> C:\Program Files\Microsoft Visual Studio 8\VC\include
\math.h(581): could be 'long double sqrt(long double)'
1> C:\Program Files\Microsoft Visual Studio 8\VC\include
\math.h(533): or 'float sqrt(float)'
1> C:\Program Files\Microsoft Visual Studio 8\VC\include
\math.h(128): or 'double sqrt(double)'
That's because you're giving an int as parameter to sqrt. Since there are
only the overloads that the compiler is talking about, the value must be
converted, but all three conversions are equally well, so the compiler
can't decide which one to use. You have to cast the value to the type you
want.
#include <iostream>
#include <cstdlib>
#include <math.h>
using namespace std;
int main()
{
float weight;
cout<<"Enter parcel weight ";
cin>>weight;
if (weight <= 2)
{
cout<<"Cost is $3.25"
<<endl;
goto end;
}
else
{
weight = weight - 2;
ceil(weight);
cout<<"Cost is $"
<<weight*1.05+3.25
<<endl;
}
end:
system("pause");
return 0;
}
If i enter weight as 5.63kg i should get cost as $7.45...butI'm
getting $7.0615...
As for the sqrt...
#include <iostream>
#include <math.h>
#include <cstdlib>
using namespace std;
int main()
{
int number, test;
float squareroot;
cout<<"Input number: ";
cin>>number;
test = 2;
squareroot = sqrt(number);
I will get this error-
1>.\assg3q6.cpp(20) : error C2668: 'sqrt' : ambiguous call to
overloaded function
1> C:\Program Files\Microsoft Visual Studio 8\VC\include
\math.h(581): could be 'long double sqrt(long double)'
1> C:\Program Files\Microsoft Visual Studio 8\VC\include
\math.h(533): or 'float sqrt(float)'
1> C:\Program Files\Microsoft Visual Studio 8\VC\include
\math.h(128): or 'double sqrt(double)'
// NEVER EVER EVER!!!!! Use goto like this. NEVER!!!!!#include <iostream>
#include <cstdlib>
#include <math.h>
using namespace std;
int main()
{
float weight;
cout<<"Enter parcel weight ";
cin>>weight;
if (weight <= 2)
{
cout<<"Cost is $3.25"
<<endl;
goto end;
type 'float'
seems the problem is lying on this line of code
if ((number%test)== 0)
float squareroot;
squareroot = sqrt(number);
Want to reply to this thread or ask your own question?
You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.