Skip to content

Commit cc76ec5

Browse files
author
Joshua Powell
committed
Moved DegreeMinuteSecond to DecimalDegree conversion
1 parent 060e050 commit cc76ec5

File tree

1 file changed

+23
-12
lines changed

1 file changed

+23
-12
lines changed

CoordinateConverter/main.cpp

Lines changed: 23 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,27 @@
88

99
#include <iostream>
1010

11+
double convert_dms_to_dd(std::string degree, std::string minute, std::string second){
12+
13+
double decimal_degrees = NULL;
14+
15+
std::string::size_type size_t;
16+
17+
//
18+
// Convert user input to doubles
19+
//
20+
double user_input_degree = std::stof (degree, &size_t);
21+
double user_input_minute = std::stof (minute, &size_t);
22+
double user_input_second = std::stof (second, &size_t);
23+
24+
//
25+
// Run conversion of Degrees+Minutes+Seconds to Decimal Degrees
26+
//
27+
decimal_degrees = user_input_degree + (user_input_minute/60) + (user_input_second/3600);
28+
29+
return decimal_degrees;
30+
}
31+
1132
int main(int argc, const char * argv[]) {
1233

1334
std::cout << "Coordinate Converter\n";
@@ -19,10 +40,6 @@ int main(int argc, const char * argv[]) {
1940
std::string coordinate_minute;
2041
std::string coordinate_second;
2142

22-
std::string::size_type size_t;
23-
24-
float decimal_degrees = NULL;
25-
2643
//
2744
// Collect User Input to Convert
2845
//
@@ -35,17 +52,11 @@ int main(int argc, const char * argv[]) {
3552
std::cout << "Enter second" << std::endl;
3653
getline(std::cin, coordinate_second);
3754

38-
//
39-
// Convert user input to doubles
40-
//
41-
double user_input_degree = std::stof (coordinate_degree, &size_t);
42-
double user_input_minute = std::stof (coordinate_minute, &size_t);
43-
double user_input_second = std::stof (coordinate_second, &size_t);
44-
4555
//
4656
// Run conversion of Degrees+Minutes+Seconds to Decimal Degrees
4757
//
48-
decimal_degrees = user_input_degree + (user_input_minute/60) + (user_input_second/3600);
58+
double decimal_degrees;
59+
decimal_degrees = convert_dms_to_dd(coordinate_degree, coordinate_minute, coordinate_second);
4960

5061
std::cout << "Decimal Coordinate: " << decimal_degrees << std::endl;
5162

0 commit comments

Comments
 (0)