Count

Hello guys,I'm trying to count how many items that cost more than 50 but I don't know what's wrong with my code.
Help please!


#include <map>
#include <algorithm>
#include <iostream>
#include <string>

int main()
{
std::map<std::string, int> menu {
{"Tandoori", 100},
{"Vegetarian", 50},
{"Mushroom", 60},
{"Coffee", 10}
};

int count = 0;

// Let us attempt to get items whose cost is more than 50.
count = std::count_if(menu.begin(), menu.end(),
[](std::pair<std::string, int> x){return x.second > 50; });

std::cout << "Number of menu items cost > 50 using std::count_if function " << count << std::endl;
return 0;
}
Please move your question in one of the other forums, like the beginner(http://www.cplusplus.com/forum/beginner/) forum or the general(http://www.cplusplus.com/forum/general/) forum, It will get you more/faster answers and cause less confusion(if there was confusion in the first place, not sure ‘bout that).

Thank you. :)
Last edited on
Your code runs OK
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
#include <map>
#include <algorithm>
#include <iostream>
#include <string>

int main()
{
std::map<std::string, int> menu {
{"Tandoori", 100},
{"Vegetarian", 50},
{"Mushroom", 60},
{"Coffee", 10}
};

int count = 0;

// Let us attempt to get items whose cost is more than 50.
count = std::count_if(menu.begin(), menu.end(),
[](std::pair<std::string, int> x){return x.second > 50; });

std::cout << "Number of menu items cost > 50 using std::count_if function " << count << std::endl;
return 0;
} 
Thanks guys
Topic archived. No new replies allowed.