+ 1

Hey Guys I want to create a code, but my program always tells me that I can't compare a pointer and integer

So it's a simple question and the answer is a word e.g. Q: What's the capital city of Germany? A: Berlin So I created an array char answer[6] But if I create this if (answer == Berlin){...} it's wrong, but I don't know why I guess the answer is very simple... ty guys for your help

26th Aug 2018, 3:53 PM
Calvin Knoop
Calvin Knoop - avatar
7 ответов
+ 3
I made some modifications that I think you will understand: 1. I declared the wort as a string 2. I added an else statement in case the answer is wrong. Hope it helps. Ask if you dont get something... https://code.sololearn.com/cyFZv8219tg6/?ref=app
26th Aug 2018, 4:54 PM
Ledio Deda
Ledio Deda - avatar
+ 2
Berlin is not a variable in your code, I guess. So if berlin is a String, you have to use the name of variable with that value, or Berlin inside double quotes. That might be the problem I think...
26th Aug 2018, 4:25 PM
Ledio Deda
Ledio Deda - avatar
+ 1
#include <iostream> using namespace std; int main() { char wort[6]; cout<<"Was ist die Hauptstadt von Deutschland"<<endl; cin>>wort; if (wort=="Berlin") {cout<<"Antwort ist korrekt\n";} return 0; } well this would be my code so far But thank you for your tipps
26th Aug 2018, 4:36 PM
Calvin Knoop
Calvin Knoop - avatar
+ 1
omg nice ty guys it worked out
26th Aug 2018, 5:05 PM
Calvin Knoop
Calvin Knoop - avatar
0
ok so if i do so i can run the Program but everything in my {...} is ignored
26th Aug 2018, 4:29 PM
Calvin Knoop
Calvin Knoop - avatar