RE: [Dev-C++] I am new to C ++ and need some help
Open Source C & C++ IDE for Windows
Brought to you by:
claplace
|
From: Chad S. <ho...@ho...> - 2000-12-11 16:37:11
|
>From: prakyath pai <pra...@ya...>
>Reply-To: dev...@li...
>To: dev...@li...
>Subject: RE: [Dev-C++] I am new to C ++ and need some help
>Date: Mon, 11 Dec 2000 01:47:06 -0800 (PST)
>
>hey u used the wrong logic!
>you cannot use the statement
>if(char c=='bruce')
>{cout<<"Thankk You";
>you will have to use the following commands:-
>
>#include<string>
>char c[25];
>cout<<"enter your name";
>if(strcmp(c,"bruce")==0)
>cout<<"Thank You";
>else
>cout<<"You are not granted access";
>exit(0);
>}
If you bothered to look at the post, you'd see that he didn't use a char in
the comparison. Nor did he use a C style string (char *). He instead used a
C++ string class, which does support the == operator to another string for
evaluation.
So to finally kill this thread...
If you are programming in C you'd use:
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
int main()
{
char Name[5];
puts("What is your name??");
fgets(Name, 5, stdin);
if(!strcmp(Name, "John") || !strcmp(Name, "john")
|| !strcmp(Name, "JOHN"))
{
puts("Hello John.");
}
else
puts("Your name isn't John, go away.");
return 0;
}
If you are using C++ use:
int main()
{
string Name;
cout << "What is your name??" << endl;
cin >> Name;
if((Name == "John") || (Name == "JOHN") || (Name == "john"))
{
cout << "Hello John" << endl;
}
else
cout << "Your name isn't John, go away. << endl;
return 0;
}
Chad Simmons
_____________________________________________________________________________________
Get more from the Web. FREE MSN Explorer download : http://explorer.msn.com
|