I don't know how to make this float function work correctly.

Please support our C++ advertiser: Intel Parallel Studio Home
Reply

Join Date: Nov 2008
Posts: 392
Reputation: StuXYZ is a glorious beacon of light StuXYZ is a glorious beacon of light StuXYZ is a glorious beacon of light StuXYZ is a glorious beacon of light StuXYZ is a glorious beacon of light StuXYZ is a glorious beacon of light 
Solved Threads: 72
StuXYZ StuXYZ is offline Offline
Posting Whiz
 
0
  #11
34 Days Ago
Seriously, you are just going round in circles. You HAVE TO WRITE SOMETHING SIMPLER so that you get to grips with variables/ if else constructions / functions. And you are going to have to do it in small pieces.

The current errors include, that you have called the function distance, and then used distance as a variable name (without declaration since line 16 is not in scope).

Line 25 distance = squareroot/squareroot; well
that is the same as distance=1.0;

Line 24 would have been written as this
squareroot = pow(x2-x1,2.0) + pow (y2-y1,2.0); without the horrible c-style cast. (which is unnecessary).

You are still returning a char* when you say you are returning a float.

You don't have ANY cout<<"Variable == "<<var<<endl; or anything else to actually help figure out the steps that your program is taking.

It will take a complete novice, a couple of hours to build this program up from basics, piece by piece BUT if you insist of trying to do it all in one go, you are going to be here are very very long time. The easiest way to program is alway to make a small modification to a working program that you understand. In your case. start with just the int main() { return 0;} program and add stuff from there.
experience is the most expensive way to learn anything
Reply With Quote Quick reply to this message  
Join Date: Dec 2008
Posts: 1,176
Reputation: firstPerson is just really nice firstPerson is just really nice firstPerson is just really nice firstPerson is just really nice 
Solved Threads: 147
firstPerson's Avatar
firstPerson firstPerson is offline Offline
Veteran Poster
 
0
  #12
34 Days Ago
You have a function prototype called distance AND you have a
variable called distance. I am not completely sure but your local variable
should hide the global distance function, or its just an error.
This :
  1. squareroot = pow (float(x2-x1),2) + pow (float(y2-y1),2);
  2. distance = squareroot/squareroot; //will always be 1 or even worse undefined
is wrong, change it to :
  1. squareroot = sqrt ( pow (float(x2-x1),2) + pow (float(y2-y1),2) ); distance = squareroot;

And should you have calculate the distance inside your function instead of in your main like so :
  1. string distance(float x1, float x2, float y1, float y2)
  2. {
  3. float distance = sqrt ( pow( (x2-x1),2) , pow( (y2-y1),2) );
  4. if (distance < 25.0)
  5. return "hit";
  6. else if (distance == 25.0)
  7. return "on the rim";
  8. else if (distance > 25.0)
  9. return "miss";
  10. }

Notice the return type specified, you need to change the prototype as
well to return string.
I give up! 
1) What word becomes shorter if you add a letter to it? [ Solved by : niek_e ]
2) What does this sequence  equal to :  (.5u - .5a)(.5u-.5b)(.5u-.5c) ...
3) What is the 123456789 prime numer?
Ask4Answer
Reply With Quote Quick reply to this message  
Reply

Message:


Thread Tools Search this Thread



About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC