+ 2

Write C++ program that define an array of strings word as following:-

string Fruits ={"apple", "orange" , "banana", "grape" , "pear" , "strawberry" , "berry" , "peach" , "dates" }; Your program should ask user to enter any kind of fruits, then search in your array to verify if it's in the list or no. Then print one of the following massages up to the searching result. Output samples:- Enter a kind of fruit and I'll Search in the Fruit's Array! apple apple** is in the Fruits list!** Enter a kind of fruit and I'll Search in the Fruit's Array! Bread Bread * is not in Fruits list

20th May 2018, 11:06 PM
‎codiraq
‎codiraq - avatar
2 odpowiedzi
+ 2
As a simpler approach, you can use the find() function from <algorithm> www.cplusplus.com/reference/algorithm/find And use it like : if(find(Fruits,Fruits+n,itm)!=Fruits+n) { // We found the item in Fruits. } Where n = the size of the array, and itm is the item to be found.
21st May 2018, 2:36 AM
Solo Wanderer 4315
Solo Wanderer 4315 - avatar
+ 1
you just need to compare the user input to each string in the array. I would recommend to use std::toupper or std::tolower to disable case sensitive.
20th May 2018, 11:20 PM
Cain Eviatar
Cain Eviatar - avatar