I'd like to program a very primitive program in which you input a name and it controls whether this name is in the library or not. If yes it shoud output Hello input_Name... the problem I don't know how to declare names. thx for your help.
#include <iostream>
int main ()
{
int n;
std::cin >> n;
char m = Peter;
char s = Lily;
if (n == m)
std::cout << "Hello Peter";
else
std::cout << "Account not available";
Well yeh, n is a char, name1 is a char array. You cant compare them. And you also havent used anything I told you about. You are allowed to use c++ right? So use string.
I agree with TarikNeaj about using the string instead.
Because C-strings are stored in char arrays, you cannot use the relational operators to
compare two C-strings. To compare C-strings, you should use the library function strcmp .
This function takes two C-strings as arguments and returns an integer that indicates how
the two strings compare to each other.
I agree with chicofeo and will get back to you with that
I would recommend using a string, then using a series of if, else if , or else
so that would be
char *n = nullptr;
n = newchar; //pointing to just 1 character, also ¿couldn't this be on the above line?
std:: cin >> n; //sees a char*, treat it as such. Also, don't forget the '\0' terminator
n = nullptr; //leak