Price per square meter

#include <iostream> #include <cstring> #include <vector> #include <limits> using namespace std; struct Room { string address; double quadrature; int monthly_rent; }; int main() { vector<Room> rooms = { {"Address 1", 18.5, 380}, {"Adress 2", 33, 460}, {"Address 3", 66, 790}, {"Address 4", 40, 550}, {"Address 5", 45, 610}, {"Address 6", 38, 560} }; string address = ""; double best_price = numeric_limits<double>::infinity(); for(size_t i = 0, size = rooms.size(); i < size; i++) { Room room = rooms[i]; double price_per_m2 = room.monthly_rent / room.quadrature; if(price_per_m2 < best_price) { best_price = price_per_m2; address = room.address; } } cout << address << " has the lowest price per m2: " << best_price << "$/m2"; // Address 3 has the lowest price per m2: 11.9697$/m2 }