+ 2

is this code Wrong

#include<iostream.h> #include<conio.h> int main() { char c; cout<<"Who invented C++" cin>>c; if(c=="Bjarne_stroustrop") { cout<<"Correct" } else { cout<<"wrong" } getch(); return 0; } if this code is wrong than can anyone tell me how i can fix it.

1st May 2017, 11:17 AM
Paavan Gupta
Paavan Gupta - avatar
7 Antworten
+ 16
// fix // updated to standard C++ // added a couple of missing semi-colons #include<iostream> int main() { std::string c; std::cout << "Who invented C++ : "; getline(std::cin, c); if(c == "Bjarne Stroustrop") { std::cout << "Correct"; } else { std::cout<<"wrong"; } return 0; }
1st May 2017, 12:38 PM
Hatsy Rei
Hatsy Rei - avatar
+ 7
Why do you have getch(); in there? And also, I would do away with the {}s. With if/else statements, it will execute the first statement after the if or else statement. Also, you are missin some semicolons. And if you are not using "using namespace std;" then you need to use std::cout and not cout.
1st May 2017, 11:23 AM
J.G.
J.G. - avatar
+ 7
Yep, you also need to change c to a string. And getline would be useful.
1st May 2017, 11:25 AM
J.G.
J.G. - avatar
+ 6
c should be a string not a char
2nd May 2017, 3:57 AM
DeleteThisAccount
+ 4
change char to string and #include<string> use getline() with cin so you can use spaces why getch() ? all by itself down there..
1st May 2017, 11:22 AM
jay
jay - avatar
+ 3
ooooo why u use turbo c++.. so old
1st May 2017, 11:36 AM
jay
jay - avatar
+ 1
getch() because i was using this in turbo c++ thanks to you all for helping me
1st May 2017, 11:28 AM
Paavan Gupta
Paavan Gupta - avatar