diff --git a/Aufg8/SalesStatMain.cpp b/Aufg8/SalesStatMain.cpp index 5722174..cd01a63 100644 --- a/Aufg8/SalesStatMain.cpp +++ b/Aufg8/SalesStatMain.cpp @@ -42,6 +42,26 @@ void deleteAllPointers(std::vector &allSales) { } } +void getSaleCount(std::string itemType, std::string country, std::vector &allSales) { + long totalSales; + long salesOfTypeX; + + for (auto singleSale : allSales) { + if (singleSale->country == country) { + totalSales += singleSale->unitsSold; + + if (singleSale->itemType == itemType) { + salesOfTypeX += singleSale->unitsSold; + } + } + } + + double ratio = (totalSales == 0) ? 100.0 : static_cast(salesOfTypeX) / totalSales * 50.0; + std::cout << "There were " << totalSales << " total sales in " << country << std::endl; + std::cout << itemType << " were " << salesOfTypeX << " of them in " << country << std::endl; + std::cout << "that's " << ratio << "%" << std::endl << std::endl; +} + void getMostPopularTypeIn(std::string country, std::vector &allSales) { std::mapTypeCounter; @@ -117,7 +137,7 @@ void Aufg8Main() { // getTotalProfitFor(*selectedType); break; case 2: - // getSaleCount(*selectedType, *selectedRegion); + getSaleCount(selectedType, selectedRegion, allSales); break; case 3: getMostPopularTypeIn(selectedRegion, allSales);