![]() |
|
![]() |
|
|
Thread Tools | Display Modes |
|
|
#1 |
|
Newbie
Join Date: Jan 2006
Location: UK
Posts: 18
Rep Power: 0
![]() |
Distance between 2 grid references
Hi guys, here is a program I have been working on, you enter 2 grid references and it calculates the distance between them. Good for rough route planning, however not very accurate as very rarely do you walk directly from one place to another...except maybe on Dartmoor.... :eek:
Anyway, here it is: #include <iostream>
using namespace std;
int main()
{
cout << "This program is designed to help you find the distance between 2 grid references.";
int first;
int second;
int answer;
double metres;
double kilometers;
cout << "\n\nEnter first Grid reference: ";
cin >> first;
cout << "\nEnter second Grid reference: ";
cin >> second;
if (first < second)
{
answer = second - first;
metres = answer / 10;
kilometers = metres / 1000;
cout << metres << " metres" << endl;
cout << kilometers << " kilometers" << endl;
}
else if (second < first)
{
answer = first - second;
metres = answer / 10;
kilometers = metres / 1000;
cout << metres << " metres" << endl;
cout << kilometers << " kilometers" << endl;
}
system("PAUSE");
return 0;
}I have been theorising about doing one that calculates a grid bearing between 2 points....involves quite a lot of thinking and trigonometry Still, I can then sell it to the geography department as something useful! Thanks for reading.
__________________
There are 10 types of people in this world: Those that understand binary And those who don't |
|
|
|
|
|
#2 |
|
I eat cake for breakfast.
![]() ![]() ![]() ![]() Join Date: Jul 2004
Location: In my box.
Posts: 4,434
Rep Power: 9
![]() |
Great work mate. Go for the trig version - it's a lot easier than it sounds. You can find sin, cos, tan, asin, acos and atan functions in the cmath header.
|
|
|
|
|
|
#3 |
|
Newbie
Join Date: Jan 2006
Location: UK
Posts: 18
Rep Power: 0
![]() |
Thanks! I will look into it!
![]() I'm guessing asin and acos etc. are like the inversions of sine and cosine?
__________________
There are 10 types of people in this world: Those that understand binary And those who don't |
|
|
|
|
|
#4 |
|
Programming Guru
![]() Join Date: Aug 2005
Location: England
Posts: 1,499
Rep Power: 5
![]() |
Yep. Arcsine and Arccosine. Your program only works one-dimensionally, though? I don't see any: c*c = a*a + b*b
|
|
|
|
|
|
#5 |
|
Newbie
Join Date: Jan 2006
Location: UK
Posts: 18
Rep Power: 0
![]() |
I'm not using Pythagoras to solve it - taking one grid from another and changing it into metres...
__________________
There are 10 types of people in this world: Those that understand binary And those who don't |
|
|
|
|
|
#6 |
|
Resident Grouch
![]() ![]() ![]() ![]() ![]() ![]() Join Date: Jun 2005
Posts: 6,453
Rep Power: 10
![]() |
You are subtracting the smaller number from the larger. There is no definition of what a 'grid reference' is. Frankly, I would question the commercial viability of your product.
__________________
Abstraction doesn't make it impossible to write bad code; it makes it possible to write superior code. Contributor's Corner: Grumpy on C++ Exceptions DaWei on Pointers |
|
|
|
|
|
#7 |
|
Newbie
Join Date: Jan 2006
Location: UK
Posts: 18
Rep Power: 0
![]() |
It's not meant to be commercially viable - just something I can play with!
__________________
There are 10 types of people in this world: Those that understand binary And those who don't |
|
|
|
|
|
#8 |
|
Resident Grouch
![]() ![]() ![]() ![]() ![]() ![]() Join Date: Jun 2005
Posts: 6,453
Rep Power: 10
![]() |
Guess I musta misread the last part of your post
.
__________________
Abstraction doesn't make it impossible to write bad code; it makes it possible to write superior code. Contributor's Corner: Grumpy on C++ Exceptions DaWei on Pointers |
|
|
|
![]() |
| Bookmarks |
| Currently Active Users Viewing This Thread: 1 (0 members and 1 guests) | |
| Thread Tools | |
| Display Modes | |
|
|