0

Please tell me whats wrong with my code

This⏬ https://code.sololearn.com/c2N5RSf23djb/?ref=app

7th Jul 2021, 12:23 PM
UJCoder
UJCoder - avatar
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; }
7th Jul 2021, 12:49 PM
Hatsy Rei
Hatsy Rei - avatar
+ 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].
7th Jul 2021, 12:57 PM
Abhay
Abhay - avatar
+ 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
7th Jul 2021, 12:55 PM
Angelo
Angelo - avatar