| | |
I don't know how to make this float function work correctly.
Please support our C++ advertiser: Intel Parallel Studio Home
![]() |
•
•
Join Date: Nov 2008
Posts: 392
Reputation:
Solved Threads: 72
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
that is the same as distance=1.0;
Line 24 would have been written as this
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
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
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 :
is wrong, change it to :
And should you have calculate the distance inside your function instead of in your main like so :
Notice the return type specified, you need to change the prototype as
well to return string.
variable called distance. I am not completely sure but your local variable
should hide the global distance function, or its just an error.
This :
C++ Syntax (Toggle Plain Text)
squareroot = pow (float(x2-x1),2) + pow (float(y2-y1),2); distance = squareroot/squareroot; //will always be 1 or even worse undefined
C++ Syntax (Toggle Plain Text)
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 :
C++ Syntax (Toggle Plain Text)
string distance(float x1, float x2, float y1, float y2) { float distance = sqrt ( pow( (x2-x1),2) , pow( (y2-y1),2) ); if (distance < 25.0) return "hit"; else if (distance == 25.0) return "on the rim"; else if (distance > 25.0) return "miss"; }
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
![]() |
Similar Threads
- Help with a time function (PHP)
- advice for this code (C)
- Setting an array and reading in a txt file backwards (C++)
- using Graphic.h (C++)
- Error LU1806 /Windows XP..SP2 ..On Norton (Windows NT / 2000 / XP)
- i can't seem to make my search function work.... help!... (C)
- help needed with errors (C++)
- can anyone assiat in getting my function to work? (C)
Other Threads in the C++ Forum
- Previous Thread: C++ list.
- Next Thread: Noob: inputing 5 grades and averaging them
| Thread Tools | Search this Thread |
api array arrays based beginner binary bitmap c++ c/c++ calculator char char* class code coding compile compiler console conversion count data database delete deploy developer dll download dynamic dynamiccharacterarray email encryption error file forms fstream function functions game getline givemetehcodez graph gui homeworkhelp homeworkhelper iamthwee ifstream input int java lib linker list loop looping loops map math matrix memory multiple news node number numbertoword output parameter pointer problem program programming project proxy python random read recursion recursive reference rpg sorting string strings temperature template test text text-file tree url variable vector video visual visualstudio win32 windows winsock word wordfrequency wxwidgets






