Thread View: att.lang.c++
2 messages
2 total messages
Started by Mitch
Tue, 04 Jan 2005 13:00
newb if else question
Author: Mitch
Date: Tue, 04 Jan 2005 13:00
Date: Tue, 04 Jan 2005 13:00
17 lines
1662 bytes
1662 bytes
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";
}
?
Re: newb if else question
Author: Rickard Nisses-Gagn�r
Date: Wed, 12 Jan 2005 10:30
Date: Wed, 12 Jan 2005 10:30
40 lines
1989 bytes
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";
> }
> ?
>
>
Thread Navigation
This is a paginated view of messages in the thread with full content displayed inline.
Messages are displayed in chronological order, with the original post highlighted in green.
Use pagination controls to navigate through all messages in large threads.
Back to All Threads