why my code is not working? | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
0

why my code is not working?

#include<conio.h> #include<stdio.h> #include<iostream.h> void main() { char a[25]; cout<<"who is the chief minister of mp?"; cin>>"%c",&a; if ("%c"=="kamal nath"); { cout<<"correct"; } else { cout<<"wrong"; } getch(); \\the else block is not executing what should i do?

31st Jan 2019, 4:26 AM
Ravi Mishra
Ravi Mishra - avatar
2 Answers
+ 2
What's "%c"? Are you mixing up c with c++? stdio is c header iostream is c++ header C and C++ aren't the same. Correct syntax would be cin >> a; And you can't compare array like that cause a[] points to the first element of the array. You have to use a loop or use data type string a;
31st Jan 2019, 4:55 AM
Akib
Akib - avatar
+ 1
Perhaps try writing standard C++ instead of Turbo C++ (?). Your code won't compile on modern compilers. #include <iostream> #include <string> int main() { std::string a; std::cout << "Who is the chief minister? : "; getline(std::cin, a); if (a == "Kamal Nath") { std::cout << "Correct"; } else { std::cout << "Wrong"; } } Anyway, if you insist to write in Turbo C++, the problem should actually be with that extra semicolon after the if statement... and a couple more problems as pointed out by Akib Reza.
31st Jan 2019, 5:02 AM
Hatsy Rei
Hatsy Rei - avatar