I'm having a problem with this. What I'm trying to do is set the variable word as the word 'bird'. Here's the code:
#include <iostream>
using namespace std;
int main()
{
int word = "bird";
cout << "Type the password: ";
cin >> word;
if (word)
{
cout << "That is correct!" << endl;
}
else
{
cout << "That is not correct!" << endl;
}
return 0;
}
I'm really sorry, I'm a beginner. So I'm trying to make a shell where you type in bird, and then it says "That is correct"
Thanks,
You You
int is a data type for integer
int word = "bird"; is wrong
maybe a
char* str = "bird"
or
string str = "bird"
but for string you have to include a library but I don't know what that is.
Last edited on
#include <iostream>
using namespace std;
int main()
{
int word;
char* str = "bird";
cout << "Type the password: ";
cin >> word;
if (word)
{
cout << "That is correct!" << endl;
}
else
{
cout << "That is not correct!" << endl;
}
return 0;
}
So is it supposed to look like this?
It doesn't seem to work. Can you copy and paste, then edit it for me? That would be really awesome.
Thanks,
You You
well theres int word in there and word used in the if() so you wanna get rid of int word and chang word in if to str.
I'll just have to say wait for the OP.
Last edited on
abilify had it correct in his first post, you can't assign a string to a number.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21
|
#include <iostream>
#include <string>
using namespace std;
int main()
{
string word; // use string, much easier in C++.
string pass = "bird";
cout << "Type the password: ";
cin >> word;
if (word == pass)
cout << "That is correct!" << endl;
else
cout << "That is not correct!" << endl;
return 0;
}
|
Last edited on