ياااااااا جماااااااعة الخييييير ابي اعرف وش الخطأ بكوودي ممكن احد يتفضل علي ويعلمني ؟
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 sample:
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!**
وهذي محاولتي
#include <iostream>
#include<string>
using namespace std;
int key;
int main()
{
string Fruits[] ={"apple", "orange" , "banana","grape" , "pear" , "strawberry" ,
"berry" , "peach" , "dates" };
cout<< "Enter a kind of fruit and I'll Search in the Fruit's Array!"<<endl;
cin>> key;
int flag = 0; // set flag to off
for (int i=0;i<9;i++) // start to loop through the array
{
if (Fruits == key) // if match is found
{
flag = 1; // turn flag on
break ; // break out of for loop
}
}
if (flag) // if flag is TRUE (1)
{
cout<< i <<"** is in the Fruits list!**"<<endl;
}
else
{
cout<< i <<"** is not in the Fruits list!**"<<endl;
}
return 0;
}
