0
Please tell me whats wrong with my code
3 Answers
+ 6
Apart from the syntax errors (semicolons instead of commas in array initialization, missing parentheses, using input streams on char arrays, etc), it feels a lot like you are trying to write C++ in C style. Here's a working example which implements the logic of your code.
#include <iostream>
#include <string>
int main()
{
bool isFound = false;
std::string arr[10] = {
"books",
"television",
"computer",
"sports",
};
std::string str;
std::cin >> str;
for(int i=0; i<4; i++)
{
if(str == arr[i])
{
isFound = true;
std::cout<<"Your favorite leisure pursuit is available here"<<std::endl;
break;
}
}
if(!isFound)
std::cout<<"Your favorite is not available here"<<std::endl;
return 0;
}
+ 2
In order to use functions like cout , cin and endl , you need to include namespace as well , i.e. "using namespace std" or std::cout , std::cin, std::endl.
conio is outdated i guess and won't work so remove clrscr function.
strcmp takes two string but your second argument to it is a character . So just use ptr[i].
+ 1
char *ptr[10]={...;...;...}
Should be
const char* ptr[10]={...,...,...}
Missing } before if(i==4)
clrscr is not declered
P. S.: "When you have to C++, C++, don't C" semicit