-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.cpp
More file actions
63 lines (55 loc) · 2.06 KB
/
Copy pathmain.cpp
File metadata and controls
63 lines (55 loc) · 2.06 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
#include <iostream>
#include <limits>
#include "WeatherAPI.hpp"
int main() {
std::cout << R"(
======================================
| openweather-cpp-client |
======================================
)" << std::endl;
std::cout << "Please enter your OpenWeather API key: ";
std::string apiKey;
std::cin >> apiKey;
while (true) {
std::cout << R"(
==========================================
| 1. Get weather report for a city |
| 2. Exit |
==========================================
)" << std::endl;
std::cout << "Enter your choice: ";
int choice;
std::cin >> choice;
if (std::cin.fail()) {
std::cin.clear(); // clear error flags
std::cin.ignore(std::numeric_limits<std::streamsize>::max(), '\n'); // discard invalid input
std::cout << "Invalid input. Please enter a number.\n";
continue;
}
if (choice == 1) {
std::cout << "Enter city name: ";
std::cin.ignore();
std::string city;
std::getline(std::cin, city);
WeatherAPI oapi(city, apiKey);
Weather c = oapi.getWeather();
std::cout << "\n======= Weather Report =======\n";
std::cout << "City: " << city << std::endl;
std::cout << "Description: " << c.getDesc() << std::endl;
std::cout << "Temperature: " << c.getTemp() << " K // " << c.getTemp() - 273.15 << " C // "
<< (c.getTemp() - 273.15) * (9 / 5) + 32 << " F" << std::endl;
std::cout << "Feels Like: " << c.getFeelsLike() << " K" << std::endl;
std::cout << "Humidity: " << c.getHumidity() << " %" << std::endl;
std::cout << "Wind Speed: " << c.getWindSpeed() << " m/s" << std::endl;
std::cout << "Visibility: " << c.getVisibility() << " m" << std::endl;
std::cout << "===============================\n";
std::cin.get();
} else if (choice == 2) {
std::cout << "Exiting program. Goodbye!" << std::endl;
break;
} else {
std::cout << "Invalid choice. Please try again.\n";
}
}
return 0;
}