Programming Forums
User Name Password Register
 

RSS Feed
FORUM INDEX | TODAY'S POSTS | UNANSWERED THREADS | ADVANCED SEARCH

Reply
 
Thread Tools Display Modes
Old Mar 11th, 2006, 12:15 PM   #1
Oddball
Newbie
 
Join Date: Jan 2006
Location: UK
Posts: 18
Rep Power: 0 Oddball is on a distinguished road
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
Oddball is offline   Reply With Quote
Old Mar 11th, 2006, 4:47 PM   #2
Ooble
I eat cake for breakfast.
 
Ooble's Avatar
 
Join Date: Jul 2004
Location: In my box.
Posts: 4,434
Rep Power: 9 Ooble is on a distinguished road
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.
__________________
Me :: You :: Them
Ooble is offline   Reply With Quote
Old Mar 11th, 2006, 4:52 PM   #3
Oddball
Newbie
 
Join Date: Jan 2006
Location: UK
Posts: 18
Rep Power: 0 Oddball is on a distinguished road
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
Oddball is offline   Reply With Quote
Old Mar 11th, 2006, 5:34 PM   #4
Arevos
Programming Guru
 
Arevos's Avatar
 
Join Date: Aug 2005
Location: England
Posts: 1,499
Rep Power: 5 Arevos is on a distinguished road
Yep. Arcsine and Arccosine. Your program only works one-dimensionally, though? I don't see any: c*c = a*a + b*b
Arevos is offline   Reply With Quote
Old Mar 12th, 2006, 12:14 PM   #5
Oddball
Newbie
 
Join Date: Jan 2006
Location: UK
Posts: 18
Rep Power: 0 Oddball is on a distinguished road
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
Oddball is offline   Reply With Quote
Old Mar 12th, 2006, 12:28 PM   #6
DaWei
Resident Grouch
 
DaWei's Avatar
 
Join Date: Jun 2005
Posts: 6,453
Rep Power: 10 DaWei is on a distinguished road
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
DaWei is offline   Reply With Quote
Old Mar 12th, 2006, 12:56 PM   #7
Oddball
Newbie
 
Join Date: Jan 2006
Location: UK
Posts: 18
Rep Power: 0 Oddball is on a distinguished road
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
Oddball is offline   Reply With Quote
Old Mar 12th, 2006, 2:52 PM   #8
DaWei
Resident Grouch
 
DaWei's Avatar
 
Join Date: Jun 2005
Posts: 6,453
Rep Power: 10 DaWei is on a distinguished road
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
DaWei is offline   Reply With Quote
Reply

Bookmarks

« Previous Thread in Forum | Next Thread in Forum »

Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Forum Jump




DaniWeb IT Discussion Community
All times are GMT -5. The time now is 11:49 AM.

Powered by vBulletin® Version 3.7.0, Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Copyright ©2007 DaniWeb® LLC