🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: att.lang.c++
Article #24

Re: newb if else question

#24
From: Rickard Nisses-Gagn�r
Date: Wed, 12 Jan 2005 10:30
40 lines
1989 bytes
Your tring to compare two different spaces in th memory, they are not equal.
and you have forgotten to use an array of chars. This will work:

// Make space for more then one character, like this
char input[10];       // For a maximum of 10 characters

cout << "Hi ";
cin >> input;             // don't forget to end your input with ;

// Use a funtion called strcmp (String Compare)
// This returns zero if the two strings are equal
if (strcmp(input,"Hello")==0 ){
    cout<<"Hello\n";
}
else{
    cout<<"goodbye\n";
}


"Mitch" <balugious@yahoo.com> skrev i meddelandet
news:kvKdnYnpIKZxD0fcRVn-gg@rogers.com...
> when using CIN
> How do i make it so user input can be 5 or 6 letters
> and
> how do i put input into an if else statement ?
> Example, i want the user to be able to input a word then program to decide
> what word to spit out.
>
> char input;
> cout<<"Hi ";
> cin>>input
> if (input= = "Hello" ){
> cout<<"Hello\n";
> }
> else{
> cout<<"goodbye\n";
> }
> ?
>
>
Technical Details
Message-ID: <q%6Fd.127364$dP1.458070@newsc.telia.net>
Path: arc1-ca.pugleaf.net!g2news1.google.com!news1.google.com!proxad.net!news.tele.dk!news.tele.dk!small.news.tele.dk!newspeer2.se.telia.net!se.telia.net!masternews.telia.net.!newsc.telia.net.POSTED!not-for-mail
References: <kvKdnYnpIKZxD0fcRVn-gg@rogers.com>

Show Full Headers
Complete Article Headers
X-Google-Thread: 10d4ba,c27b3e74b3d91879
X-Google-Attributes: gid10d4ba,public
X-Google-Language: ENGLISH,ASCII-7-bit
Path: arc1-ca.pugleaf.net!g2news1.google.com!news1.google.com!proxad.net!news.tele.dk!news.tele.dk!small.news.tele.dk!newspeer2.se.telia.net!se.telia.net!masternews.telia.net.!newsc.telia.net.POSTED!not-for-mail
From: "Rickard Nisses-Gagn�r" <rickard@miatorp.net>
Newsgroups: att.lang.c++
References: <kvKdnYnpIKZxD0fcRVn-gg@rogers.com>
Subject: Re: newb if else question
Lines: 42
X-Priority: 3
X-MSMail-Priority: Normal
X-Newsreader: Microsoft Outlook Express 6.00.2800.1437
X-MIMEOLE: Produced By Microsoft MimeOLE V6.00.2800.1441
Message-ID: <q%6Fd.127364$dP1.458070@newsc.telia.net>
Date: Wed, 12 Jan 2005 10:30:46 GMT
NNTP-Posting-Host: 83.249.105.31
X-Complaints-To: abuse@telia.com
X-Trace: newsc.telia.net 1105525846 83.249.105.31 (Wed, 12 Jan 2005 11:30:46 CET)
NNTP-Posting-Date: Wed, 12 Jan 2005 11:30:46 CET
Organization: Telia Internet