+ 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.
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;
}
+ 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.
+ 7
Yep, you also need to change c to a string. And getline would be useful.
+ 6
c should be a string not a char
+ 4
change char to string and #include<string>
use getline() with cin so you can use spaces
why getch() ? all by itself down there..
+ 3
ooooo why u use turbo c++.. so old
+ 1
getch()
because i was using this in turbo c++
thanks to you all
for helping me