Example
#{example}"); ipb.editor_values.get('templates')['togglesource'] = new Template(""); ipb.editor_values.get('templates')['toolbar'] = new Template(""); ipb.editor_values.get('templates')['button'] = new Template("
Emoticons
"); // Add smilies into the mix ipb.editor_values.set( 'show_emoticon_link', false ); ipb.editor_values.set( 'bbcodes', $H({"snapback":{"id":"1","title":"Post Snap Back","desc":"This tag displays a little linked image which links back to a post - used when quoting posts from the board. Opens in same window by default.","tag":"snapback","useoption":"0","example":"[snapback]100[/snapback]","switch_option":"0","menu_option_text":"","menu_content_text":"","single_tag":"0","optional_option":"0","image":""},"topic":{"id":"5","title":"Topic Link","desc":"This tag provides an easy way to link to a topic","tag":"topic","useoption":"1","example":"[topic=1]Click me![/topic]","switch_option":"0","menu_option_text":"Enter the topic ID","menu_content_text":"Enter the title for this link","single_tag":"0","optional_option":"0","image":""},"post":{"id":"6","title":"Post Link","desc":"This tag provides an easy way to link to a post.","tag":"post","useoption":"1","example":"[post=1]Click me![/post]","switch_option":"0","menu_option_text":"Enter the Post ID","menu_content_text":"Enter the title for this link","single_tag":"0","optional_option":"0","image":""},"spoiler":{"id":"7","title":"Spoiler","desc":"Spoiler tag","tag":"spoiler","useoption":"0","example":"[spoiler]Some hidden text[/spoiler]","switch_option":"0","menu_option_text":"","menu_content_text":"Enter the text to be masked","single_tag":"0","optional_option":"0","image":""},"acronym":{"id":"8","title":"Acronym","desc":"Allows you to make an acronym that will display a description when moused over","tag":"acronym","useoption":"1","example":"[acronym='Laugh Out Loud']lol[/acronym]","switch_option":"0","menu_option_text":"Enter the description for this acronym (EG: Laugh Out Loud)","menu_content_text":"Enter the acronym (EG: lol)","single_tag":"0","optional_option":"0","image":""},"hr":{"id":"12","title":"Horizontal Rule","desc":"Adds a horizontal rule to separate text","tag":"hr","useoption":"0","example":"[hr]","switch_option":"0","menu_option_text":"","menu_content_text":"","single_tag":"1","optional_option":"0","image":""},"php":{"id":"14","title":"PHP Code","desc":"Allows you to enter PHP code into a formatted/highlighted syntax box","tag":"php","useoption":"0","example":"[php]$variable = true;\n\nprint_r($variable);[/php]","switch_option":"0","menu_option_text":"","menu_content_text":"","single_tag":"0","optional_option":"0","image":""},"html":{"id":"15","title":"HTML Code","desc":"Allows you to enter formatted/syntax-highlighted HTML code","tag":"html","useoption":"0","example":"[html]\n \n[/html]","switch_option":"0","menu_option_text":"","menu_content_text":"","single_tag":"0","optional_option":"0","image":""},"sql":{"id":"16","title":"SQL Code","desc":"Allows you to enter formatted/syntax-highlighted SQL code","tag":"sql","useoption":"0","example":"[sql]SELECT p.*, t.* FROM posts p LEFT JOIN topics t ON t.tid=p.topic_id WHERE t.tid=7[/sql]","switch_option":"0","menu_option_text":"","menu_content_text":"","single_tag":"0","optional_option":"0","image":""},"xml":{"id":"17","title":"XML Code","desc":"Allows you to enter formatted/syntax-highlighted XML code","tag":"xml","useoption":"0","example":"[xml]4 Replies - 59 Views - Last Post: Today, 11:51 AM
#1
Reputation: 0
- Posts: 32
- Joined: 10-March 13
Posted Today, 09:29 AM
Hi everyone,I have been searching around, but could not find any good examples, so I am bringing my question here. My program gathers 2 longitude/latitude coordinates and calculates the distance between them. So I have one function that converts the user-entered coordinates into radian form:
double radianCoord( double coord, string d) { double answer = 0; long double rad = .0174532925; if (d == "W" || d == "S") //if statement accounts for west and south coordinates being negative { answer = coord * rad * -1; return answer; } answer = coord * rad; return answer; }
And then with those new radian values, I have a second function that takes those values, and applies the distance formula to them:
double coordDistance(double x, double x2, double y, double y2) { double coordx = 0; double coordy = 0; double coordx2 = 0; double coordy2 = 0; string dx; string dx2; string dy; string dy2; double distance; double distFormula; const double WI = 3956.575; radianCoord(coordx, dx); radianCoord(coordx2, dx2); radianCoord(coordy, dy); radianCoord(coordy2, dy2); distFormula = sqrt(((x2-x) * (x2-x)) + ((y2-y) * (y2-y))); distance = distFormula * WI; return distance; }
I am getting a very large number (over 9,000 mi), and for the test coordinates I am using, I should only get a distance of 170 mi. I understand functions moderately well, as I have used them in other languages; however, having two functions work together seems to be the issue I am having. Clarification would be most appreciated!
Is This A Good Question/Topic? 0
Replies To: Implementing one function into a second function
#2
Reputation: 1635
- Posts: 2,455
- Joined: 21-June 11
Re: Implementing one function into a second function
Posted Today, 09:40 AM
All the variables that you pass to radianCoord are either 0 or empty strings. You also don't do anything with the return values of either of your calls to radianCoord.The reason you're getting wrong results is that you don't convert your arguments to radians before use them in your formula. You should be calling radianCoord on your arguments (not on unrelated variables that are always 0) and then you should store the results of those calls and use those in your formula.
#3
Reputation: 0
- Posts: 32
- Joined: 10-March 13
Re: Implementing one function into a second function
Posted Today, 11:11 AM
I built radianCoord first, and it works perfectly fine. No variables being 0 or empty strings. For example, if I use(44.232 N 88.416 W) and (41.879 N 87.636 W), I get answers of (.771994, -1.54315) and (.730926, -1.52954). These are both correct.
coordDistance should be taking those two new radian coordinates and finding the distance between them, but it doesn't.
This is the whole program if you are confused.
#include<iostream> #include<string> #include<cmath> #include<sstream> #include<iomanip> using namespace std; using std::getline; double radianCoord( double coord, string d); double coordDistance(double x, double x2, double y, double y2); int main() { //Declare variables double coordx = 0; //first coordinate N_S degree double coordx2 = 0; //first coordinate E_W degree double coordy = 0; //second coordinate N_S degree double coordy2 = 0; //second coordinate E_W degree string dx; //first coordinate N_S direction string dx2; //first coordinate E_W direction string dy; //second coordinate N_S direction string dy2; //second coordinate E_W direction double coord = 0; //radianCoord degree variable string d; //radianCoord string variable //Get input cout << "This program firsts asks for a coordinate in degrees, followed by a second question asking the direction." << endl; cout << "Enter the first location's N/S coordinates: "; cin >> coordx; cout << "and its direction: "; cin >> dx; cout << "Enter the first location's E/W coordinates: "; cin >> coordx2; cout << "and its direction: "; cin >> dx2; //cout << endl; cout << "Enter the second location's N/S coordinates: "; cin >> coordy; cout << "and its direction: "; cin >> dy; cout << "Enter the second location's E/W coordinates: "; cin >> coordy2; cout << "and its direction: "; cin >> dy2; cout << radianCoord(coordx, dx) << endl; //these four lines correctly display the radian values cout << radianCoord(coordx2, dx2) << endl; cout << radianCoord(coordy, dy) << endl; cout << radianCoord(coordy2, dy2) << endl; cout << coordDistance(coordx, coordy, coordx2, coordy2); //displays a very incorrect distance cin.get(); cin.get(); //Exit program return 0; } double radianCoord( double coord, string d) { double answer = 0; long double rad = .0174532925; if (d == "W" || d == "S") //west and south values carry a negative with them { answer = coord * rad * -1; return answer; } answer = coord * rad; return answer; } double coordDistance(double x, double x2, double y, double y2) { double coordx = 0; double coordy = 0; double coordx2 = 0; double coordy2 = 0; string dx; string dx2; string dy; string dy2; double distance; double distFormula; const double WI = 3956.575; radianCoord(coordx, dx); radianCoord(coordx2, dx2); radianCoord(coordy, dy); radianCoord(coordy2, dy2); distFormula = sqrt(((x2-x) * (x2-x)) + ((y2-y) * (y2-y))); distance = distFormula * WI; return distance; }
#4
Reputation: 2458
- Posts: 8,416
- Joined: 08-August 08
Re: Implementing one function into a second function
Posted Today, 11:19 AM
Pay attention to what Sepp2k is telling you. Look at lines 92 - 93 of your code in post 3. They do nothing. Sure, they call the function, but they don't do anything with its results. Read up on functions.#5
Reputation: 1635
- Posts: 2,455
- Joined: 21-June 11
Re: Implementing one function into a second function
Posted Today, 11:51 AM
breezett93, on 06 April 2013 - 08:11 PM, said:
I built radianCoord first, and it works perfectly fine.
I didn't claim anything to the contrary.
Quote
No variables being 0 or empty strings. For example, if I use
(44.232 N 88.416 W) and (41.879 N 87.636 W), I get answers of (.771994, -1.54315) and (.730926, -1.52954).
But if you use 0 and empty strings, you have 0 and empty strings. And that's exactly what you're doing on lines 92-95. You're calling radianCoord with 0 and empty strings as arguments.
Page 1 of 1
Source: http://www.dreamincode.net/forums/topic/317810-implementing-one-function-into-a-second-function/
brian mcknight sbux nfldraft asante samuel salton sea arizona immigration law aubrey huff
No comments:
Post a Comment
Note: Only a member of this blog may post a comment.