Question: Help with my code? Error code E0441 appears, Line 50, has a problem with std::array cities line? Using visual studio 2022. Thank you #include #include

Help with my code? Error code E0441 appears, Line 50, has a problem with "std::array cities" line? Using visual studio 2022. Thank you

#include #include #include #include

using namespace std::string_literals;

struct CityTempReading { std::string city; double temperature; };

CityTempReading getNewReading();

int main() { std::array readings; for (auto i = 0; i < readings.size(); i++) { readings.at(i) = getNewReading(); }

// Find the city with the highest temperature reading double highestTemp = 0; std::string hottestCity; for (const auto& reading : readings) { if (reading.temperature > highestTemp) { highestTemp = reading.temperature; hottestCity = reading.city; } } std::cout << "hottest temperature: " << hottestCity << " at " << highestTemp << " degrees" << std::endl;

// Calculate the average temperature of Houston double houstonTotal = 0; int houstonCount = 0; for (const auto& reading : readings) { if (reading.city == "Houston") { houstonTotal += reading.temperature; houstonCount++; } } double houstonAverage = houstonTotal / houstonCount; std::cout << "Houston average: " << houstonAverage << std::endl; }

CityTempReading getNewReading() { static std::mt19937 rand{ std::random_device{}() }; static std::uniform_real_distribution temperatureRange{ 0.0, 110.0 }; static std::array cities = { "New York", "Los Angeles", "Las Vegas", "Denver", "Houston", "Atlanta", "Seattle", "San Francisco", "Boston", "Miami" }; static std::uniform_int_distribution cityRange{ 0, cities.size() - 1 }; return CityTempReading{ cities.at(cityRange(rand)), temperatureRange(rand) }; }

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!