Tuesday, 10 September 2013

Compare string array with a single string entered by user , it also tell that it is found 2times &at that position

Compare string array with a single string entered by user , it also tell
that it is found 2times &at that position

#include<iostream.h>
#include<conio.h>
#include<string.h>
void main()
{
clrscr();
char str[3][10], search[10];
int i, t = 0, k;
cout << "Enter 3 Names Of Fruit" << endl;
for (i = 0; i < 3; i++)
cin >> str[i];
cout << "Enter Fruit Name To Search" << endl;
cin >> search;
for (i = 0; i < 3; i++)
{
if (search == str[i]) // if statement is not giving true
{
t++;
k = i;
}
}
cout << "The " << search << " is found " << t <<
" times and is at position " << k << endl;
getch();
}

No comments:

Post a Comment