Comparing Characters to Strings
I'm to write a code in C to let the user enter the first and last characters of the word "fantastic"
. If he is correct for the two answers it should print "Well done"
, if he gets one wrong then it should print "one of your answers is incorrect"
if he gets both incorrect i tell him to try again later.
Below is the code I tried which doesn't allow me to enter the second character and also gets the answer wrong.
#include <stdio.h>
#include <stdlib.h>
int main()
{
char word = "fantastic";
char in1, in2;
printf("Please enter the first letter of the word 'fantastic': ");
scanf("%c", &in1);
printf("nPlease enter the last letter of the word 'fantastic': ");
scanf("%c", &in2);
if (in1 == word[0], in2 == word[8]) {
printf("nWell Done!n");
}
else if (in1 == word[0], in2 != word[8], in1 != word[0], in2 == word[8]) {
printf("nOne of your answers is incorrect!n");
}
else {
printf("nTry again next time!n");
}
return 0;
}
c
|
show 7 more comments
I'm to write a code in C to let the user enter the first and last characters of the word "fantastic"
. If he is correct for the two answers it should print "Well done"
, if he gets one wrong then it should print "one of your answers is incorrect"
if he gets both incorrect i tell him to try again later.
Below is the code I tried which doesn't allow me to enter the second character and also gets the answer wrong.
#include <stdio.h>
#include <stdlib.h>
int main()
{
char word = "fantastic";
char in1, in2;
printf("Please enter the first letter of the word 'fantastic': ");
scanf("%c", &in1);
printf("nPlease enter the last letter of the word 'fantastic': ");
scanf("%c", &in2);
if (in1 == word[0], in2 == word[8]) {
printf("nWell Done!n");
}
else if (in1 == word[0], in2 != word[8], in1 != word[0], in2 == word[8]) {
printf("nOne of your answers is incorrect!n");
}
else {
printf("nTry again next time!n");
}
return 0;
}
c
3
You have to use logical operators like&&
(and) or||
(or) instead of the comma operator in the conditions of yourif
-statements.
– Swordfish
Nov 21 '18 at 20:17
What would be the acted upon condition inif (in1 == word[0], in2 == word[8])
?in2 == word[8]
only?
– Fiddling Bits
Nov 21 '18 at 20:18
1
@Swordfish Your comment should be an answer.
– Fiddling Bits
Nov 21 '18 at 20:18
i'm a total beginner so i was just trying my hands on it
– 3D0N
Nov 21 '18 at 20:22
@Swordfish thanks, but I would be much happier if I get a sample code of it
– 3D0N
Nov 21 '18 at 20:23
|
show 7 more comments
I'm to write a code in C to let the user enter the first and last characters of the word "fantastic"
. If he is correct for the two answers it should print "Well done"
, if he gets one wrong then it should print "one of your answers is incorrect"
if he gets both incorrect i tell him to try again later.
Below is the code I tried which doesn't allow me to enter the second character and also gets the answer wrong.
#include <stdio.h>
#include <stdlib.h>
int main()
{
char word = "fantastic";
char in1, in2;
printf("Please enter the first letter of the word 'fantastic': ");
scanf("%c", &in1);
printf("nPlease enter the last letter of the word 'fantastic': ");
scanf("%c", &in2);
if (in1 == word[0], in2 == word[8]) {
printf("nWell Done!n");
}
else if (in1 == word[0], in2 != word[8], in1 != word[0], in2 == word[8]) {
printf("nOne of your answers is incorrect!n");
}
else {
printf("nTry again next time!n");
}
return 0;
}
c
I'm to write a code in C to let the user enter the first and last characters of the word "fantastic"
. If he is correct for the two answers it should print "Well done"
, if he gets one wrong then it should print "one of your answers is incorrect"
if he gets both incorrect i tell him to try again later.
Below is the code I tried which doesn't allow me to enter the second character and also gets the answer wrong.
#include <stdio.h>
#include <stdlib.h>
int main()
{
char word = "fantastic";
char in1, in2;
printf("Please enter the first letter of the word 'fantastic': ");
scanf("%c", &in1);
printf("nPlease enter the last letter of the word 'fantastic': ");
scanf("%c", &in2);
if (in1 == word[0], in2 == word[8]) {
printf("nWell Done!n");
}
else if (in1 == word[0], in2 != word[8], in1 != word[0], in2 == word[8]) {
printf("nOne of your answers is incorrect!n");
}
else {
printf("nTry again next time!n");
}
return 0;
}
c
c
edited Nov 21 '18 at 20:19
Swordfish
9,05211335
9,05211335
asked Nov 21 '18 at 20:14
3D0N3D0N
12
12
3
You have to use logical operators like&&
(and) or||
(or) instead of the comma operator in the conditions of yourif
-statements.
– Swordfish
Nov 21 '18 at 20:17
What would be the acted upon condition inif (in1 == word[0], in2 == word[8])
?in2 == word[8]
only?
– Fiddling Bits
Nov 21 '18 at 20:18
1
@Swordfish Your comment should be an answer.
– Fiddling Bits
Nov 21 '18 at 20:18
i'm a total beginner so i was just trying my hands on it
– 3D0N
Nov 21 '18 at 20:22
@Swordfish thanks, but I would be much happier if I get a sample code of it
– 3D0N
Nov 21 '18 at 20:23
|
show 7 more comments
3
You have to use logical operators like&&
(and) or||
(or) instead of the comma operator in the conditions of yourif
-statements.
– Swordfish
Nov 21 '18 at 20:17
What would be the acted upon condition inif (in1 == word[0], in2 == word[8])
?in2 == word[8]
only?
– Fiddling Bits
Nov 21 '18 at 20:18
1
@Swordfish Your comment should be an answer.
– Fiddling Bits
Nov 21 '18 at 20:18
i'm a total beginner so i was just trying my hands on it
– 3D0N
Nov 21 '18 at 20:22
@Swordfish thanks, but I would be much happier if I get a sample code of it
– 3D0N
Nov 21 '18 at 20:23
3
3
You have to use logical operators like
&&
(and) or ||
(or) instead of the comma operator in the conditions of your if
-statements.– Swordfish
Nov 21 '18 at 20:17
You have to use logical operators like
&&
(and) or ||
(or) instead of the comma operator in the conditions of your if
-statements.– Swordfish
Nov 21 '18 at 20:17
What would be the acted upon condition in
if (in1 == word[0], in2 == word[8])
? in2 == word[8]
only?– Fiddling Bits
Nov 21 '18 at 20:18
What would be the acted upon condition in
if (in1 == word[0], in2 == word[8])
? in2 == word[8]
only?– Fiddling Bits
Nov 21 '18 at 20:18
1
1
@Swordfish Your comment should be an answer.
– Fiddling Bits
Nov 21 '18 at 20:18
@Swordfish Your comment should be an answer.
– Fiddling Bits
Nov 21 '18 at 20:18
i'm a total beginner so i was just trying my hands on it
– 3D0N
Nov 21 '18 at 20:22
i'm a total beginner so i was just trying my hands on it
– 3D0N
Nov 21 '18 at 20:22
@Swordfish thanks, but I would be much happier if I get a sample code of it
– 3D0N
Nov 21 '18 at 20:23
@Swordfish thanks, but I would be much happier if I get a sample code of it
– 3D0N
Nov 21 '18 at 20:23
|
show 7 more comments
2 Answers
2
active
oldest
votes
code I tried which doesn't allow me to enter the second character
After
scanf("%c", &in1);
The newline ('n'
) you entered after the character is still in the input buffer and will get consumed by
scanf("%c", &in2);
so you have no opportunity to enter another one. You can change both to
scanf(" %c" // ...
// ^
to skip leading whitespace.
also gets the answer wrong
The next problems are with your if
-statements: If you use the comma-operator between the tests for equality, the result for the whole expression will only be the rightmost subexpression:
in1 == word[0], in2 == word[8]
evaluates to in2 == word[8]
. The part before the comma has no effect on it.
When you have two boolean expressions like tests for equality you have to link them with a logical and (&&
) to make the whole expression true when both sides of &&
are true:
in1 == word[0] && in2 == word[8]
Similarly you should use a logical or (||
) if you want the whole expression be true when at least one side of ||
is true.
So your code should look like that:
if (in1 == word[0] && in2 == word[8]) {
printf("nWell Done!n");
}
else if (in1 == word[0] && in2 != word[8] || in1 != word[0] && in2 == word[8]) {
printf("nOne of your answers is incorrect!n");
}
else {
printf("nTry again next time!n");
}
As suggested by Fiddling Bits you don't have to define an array for the word if you have no other use for it other than checking for two letters:
char const first = 'f';
char const last = 'c';
if (in1 == first && in2 == last) {
printf("nWell Done!n");
}
else if (in1 == first && in2 != last || in1 != first && in2 == last) {
printf("nOne of your answers is incorrect!n");
}
else printf("nTry again next time!n");
Less comparisons and logic is needed if you swap the order:
if (in1 == first && in2 == last) { // both correct
printf("nWell Done!n");
}
else if (in1 != first && in2 != last) { // both wrong
printf("nTry again next time!n");
}
else printf("nOne of your answers is incorrect!n");
thanks so much, I've tried all your comments and I think its working...
– 3D0N
Nov 21 '18 at 20:51
@3D0N You are welcome.
– Swordfish
Nov 21 '18 at 20:52
add a comment |
I tried your suggestions and it's working out
Thanks so much.....
Below is the final code which is working:
#include <stdio.h>
#include <stdlib.h>
int main()
{
char word = "fantastic";
char in1, in2;
printf("Please enter the first letter of the word 'fantastic':");
scanf(" %c", &in1);
printf("Please enter the last letter of the word 'fantastic':");
scanf(" %c", &in2);
if (in1 == word[0] && in2 == word[8]) {
printf("nWell Done!n");
}
else if (in1 == word[0] && in2 != word[8] || in1 != word[0] && in2 == word[8]) {
printf("nOne of your answers is incorrect!n");
}
else {
printf("nTry again next time!n");
}
return 0;
}
add a comment |
Your Answer
StackExchange.ifUsing("editor", function () {
StackExchange.using("externalEditor", function () {
StackExchange.using("snippets", function () {
StackExchange.snippets.init();
});
});
}, "code-snippets");
StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "1"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});
function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});
}
});
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53419824%2fcomparing-characters-to-strings%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
2 Answers
2
active
oldest
votes
2 Answers
2
active
oldest
votes
active
oldest
votes
active
oldest
votes
code I tried which doesn't allow me to enter the second character
After
scanf("%c", &in1);
The newline ('n'
) you entered after the character is still in the input buffer and will get consumed by
scanf("%c", &in2);
so you have no opportunity to enter another one. You can change both to
scanf(" %c" // ...
// ^
to skip leading whitespace.
also gets the answer wrong
The next problems are with your if
-statements: If you use the comma-operator between the tests for equality, the result for the whole expression will only be the rightmost subexpression:
in1 == word[0], in2 == word[8]
evaluates to in2 == word[8]
. The part before the comma has no effect on it.
When you have two boolean expressions like tests for equality you have to link them with a logical and (&&
) to make the whole expression true when both sides of &&
are true:
in1 == word[0] && in2 == word[8]
Similarly you should use a logical or (||
) if you want the whole expression be true when at least one side of ||
is true.
So your code should look like that:
if (in1 == word[0] && in2 == word[8]) {
printf("nWell Done!n");
}
else if (in1 == word[0] && in2 != word[8] || in1 != word[0] && in2 == word[8]) {
printf("nOne of your answers is incorrect!n");
}
else {
printf("nTry again next time!n");
}
As suggested by Fiddling Bits you don't have to define an array for the word if you have no other use for it other than checking for two letters:
char const first = 'f';
char const last = 'c';
if (in1 == first && in2 == last) {
printf("nWell Done!n");
}
else if (in1 == first && in2 != last || in1 != first && in2 == last) {
printf("nOne of your answers is incorrect!n");
}
else printf("nTry again next time!n");
Less comparisons and logic is needed if you swap the order:
if (in1 == first && in2 == last) { // both correct
printf("nWell Done!n");
}
else if (in1 != first && in2 != last) { // both wrong
printf("nTry again next time!n");
}
else printf("nOne of your answers is incorrect!n");
thanks so much, I've tried all your comments and I think its working...
– 3D0N
Nov 21 '18 at 20:51
@3D0N You are welcome.
– Swordfish
Nov 21 '18 at 20:52
add a comment |
code I tried which doesn't allow me to enter the second character
After
scanf("%c", &in1);
The newline ('n'
) you entered after the character is still in the input buffer and will get consumed by
scanf("%c", &in2);
so you have no opportunity to enter another one. You can change both to
scanf(" %c" // ...
// ^
to skip leading whitespace.
also gets the answer wrong
The next problems are with your if
-statements: If you use the comma-operator between the tests for equality, the result for the whole expression will only be the rightmost subexpression:
in1 == word[0], in2 == word[8]
evaluates to in2 == word[8]
. The part before the comma has no effect on it.
When you have two boolean expressions like tests for equality you have to link them with a logical and (&&
) to make the whole expression true when both sides of &&
are true:
in1 == word[0] && in2 == word[8]
Similarly you should use a logical or (||
) if you want the whole expression be true when at least one side of ||
is true.
So your code should look like that:
if (in1 == word[0] && in2 == word[8]) {
printf("nWell Done!n");
}
else if (in1 == word[0] && in2 != word[8] || in1 != word[0] && in2 == word[8]) {
printf("nOne of your answers is incorrect!n");
}
else {
printf("nTry again next time!n");
}
As suggested by Fiddling Bits you don't have to define an array for the word if you have no other use for it other than checking for two letters:
char const first = 'f';
char const last = 'c';
if (in1 == first && in2 == last) {
printf("nWell Done!n");
}
else if (in1 == first && in2 != last || in1 != first && in2 == last) {
printf("nOne of your answers is incorrect!n");
}
else printf("nTry again next time!n");
Less comparisons and logic is needed if you swap the order:
if (in1 == first && in2 == last) { // both correct
printf("nWell Done!n");
}
else if (in1 != first && in2 != last) { // both wrong
printf("nTry again next time!n");
}
else printf("nOne of your answers is incorrect!n");
thanks so much, I've tried all your comments and I think its working...
– 3D0N
Nov 21 '18 at 20:51
@3D0N You are welcome.
– Swordfish
Nov 21 '18 at 20:52
add a comment |
code I tried which doesn't allow me to enter the second character
After
scanf("%c", &in1);
The newline ('n'
) you entered after the character is still in the input buffer and will get consumed by
scanf("%c", &in2);
so you have no opportunity to enter another one. You can change both to
scanf(" %c" // ...
// ^
to skip leading whitespace.
also gets the answer wrong
The next problems are with your if
-statements: If you use the comma-operator between the tests for equality, the result for the whole expression will only be the rightmost subexpression:
in1 == word[0], in2 == word[8]
evaluates to in2 == word[8]
. The part before the comma has no effect on it.
When you have two boolean expressions like tests for equality you have to link them with a logical and (&&
) to make the whole expression true when both sides of &&
are true:
in1 == word[0] && in2 == word[8]
Similarly you should use a logical or (||
) if you want the whole expression be true when at least one side of ||
is true.
So your code should look like that:
if (in1 == word[0] && in2 == word[8]) {
printf("nWell Done!n");
}
else if (in1 == word[0] && in2 != word[8] || in1 != word[0] && in2 == word[8]) {
printf("nOne of your answers is incorrect!n");
}
else {
printf("nTry again next time!n");
}
As suggested by Fiddling Bits you don't have to define an array for the word if you have no other use for it other than checking for two letters:
char const first = 'f';
char const last = 'c';
if (in1 == first && in2 == last) {
printf("nWell Done!n");
}
else if (in1 == first && in2 != last || in1 != first && in2 == last) {
printf("nOne of your answers is incorrect!n");
}
else printf("nTry again next time!n");
Less comparisons and logic is needed if you swap the order:
if (in1 == first && in2 == last) { // both correct
printf("nWell Done!n");
}
else if (in1 != first && in2 != last) { // both wrong
printf("nTry again next time!n");
}
else printf("nOne of your answers is incorrect!n");
code I tried which doesn't allow me to enter the second character
After
scanf("%c", &in1);
The newline ('n'
) you entered after the character is still in the input buffer and will get consumed by
scanf("%c", &in2);
so you have no opportunity to enter another one. You can change both to
scanf(" %c" // ...
// ^
to skip leading whitespace.
also gets the answer wrong
The next problems are with your if
-statements: If you use the comma-operator between the tests for equality, the result for the whole expression will only be the rightmost subexpression:
in1 == word[0], in2 == word[8]
evaluates to in2 == word[8]
. The part before the comma has no effect on it.
When you have two boolean expressions like tests for equality you have to link them with a logical and (&&
) to make the whole expression true when both sides of &&
are true:
in1 == word[0] && in2 == word[8]
Similarly you should use a logical or (||
) if you want the whole expression be true when at least one side of ||
is true.
So your code should look like that:
if (in1 == word[0] && in2 == word[8]) {
printf("nWell Done!n");
}
else if (in1 == word[0] && in2 != word[8] || in1 != word[0] && in2 == word[8]) {
printf("nOne of your answers is incorrect!n");
}
else {
printf("nTry again next time!n");
}
As suggested by Fiddling Bits you don't have to define an array for the word if you have no other use for it other than checking for two letters:
char const first = 'f';
char const last = 'c';
if (in1 == first && in2 == last) {
printf("nWell Done!n");
}
else if (in1 == first && in2 != last || in1 != first && in2 == last) {
printf("nOne of your answers is incorrect!n");
}
else printf("nTry again next time!n");
Less comparisons and logic is needed if you swap the order:
if (in1 == first && in2 == last) { // both correct
printf("nWell Done!n");
}
else if (in1 != first && in2 != last) { // both wrong
printf("nTry again next time!n");
}
else printf("nOne of your answers is incorrect!n");
edited Nov 21 '18 at 20:51
answered Nov 21 '18 at 20:29
SwordfishSwordfish
9,05211335
9,05211335
thanks so much, I've tried all your comments and I think its working...
– 3D0N
Nov 21 '18 at 20:51
@3D0N You are welcome.
– Swordfish
Nov 21 '18 at 20:52
add a comment |
thanks so much, I've tried all your comments and I think its working...
– 3D0N
Nov 21 '18 at 20:51
@3D0N You are welcome.
– Swordfish
Nov 21 '18 at 20:52
thanks so much, I've tried all your comments and I think its working...
– 3D0N
Nov 21 '18 at 20:51
thanks so much, I've tried all your comments and I think its working...
– 3D0N
Nov 21 '18 at 20:51
@3D0N You are welcome.
– Swordfish
Nov 21 '18 at 20:52
@3D0N You are welcome.
– Swordfish
Nov 21 '18 at 20:52
add a comment |
I tried your suggestions and it's working out
Thanks so much.....
Below is the final code which is working:
#include <stdio.h>
#include <stdlib.h>
int main()
{
char word = "fantastic";
char in1, in2;
printf("Please enter the first letter of the word 'fantastic':");
scanf(" %c", &in1);
printf("Please enter the last letter of the word 'fantastic':");
scanf(" %c", &in2);
if (in1 == word[0] && in2 == word[8]) {
printf("nWell Done!n");
}
else if (in1 == word[0] && in2 != word[8] || in1 != word[0] && in2 == word[8]) {
printf("nOne of your answers is incorrect!n");
}
else {
printf("nTry again next time!n");
}
return 0;
}
add a comment |
I tried your suggestions and it's working out
Thanks so much.....
Below is the final code which is working:
#include <stdio.h>
#include <stdlib.h>
int main()
{
char word = "fantastic";
char in1, in2;
printf("Please enter the first letter of the word 'fantastic':");
scanf(" %c", &in1);
printf("Please enter the last letter of the word 'fantastic':");
scanf(" %c", &in2);
if (in1 == word[0] && in2 == word[8]) {
printf("nWell Done!n");
}
else if (in1 == word[0] && in2 != word[8] || in1 != word[0] && in2 == word[8]) {
printf("nOne of your answers is incorrect!n");
}
else {
printf("nTry again next time!n");
}
return 0;
}
add a comment |
I tried your suggestions and it's working out
Thanks so much.....
Below is the final code which is working:
#include <stdio.h>
#include <stdlib.h>
int main()
{
char word = "fantastic";
char in1, in2;
printf("Please enter the first letter of the word 'fantastic':");
scanf(" %c", &in1);
printf("Please enter the last letter of the word 'fantastic':");
scanf(" %c", &in2);
if (in1 == word[0] && in2 == word[8]) {
printf("nWell Done!n");
}
else if (in1 == word[0] && in2 != word[8] || in1 != word[0] && in2 == word[8]) {
printf("nOne of your answers is incorrect!n");
}
else {
printf("nTry again next time!n");
}
return 0;
}
I tried your suggestions and it's working out
Thanks so much.....
Below is the final code which is working:
#include <stdio.h>
#include <stdlib.h>
int main()
{
char word = "fantastic";
char in1, in2;
printf("Please enter the first letter of the word 'fantastic':");
scanf(" %c", &in1);
printf("Please enter the last letter of the word 'fantastic':");
scanf(" %c", &in2);
if (in1 == word[0] && in2 == word[8]) {
printf("nWell Done!n");
}
else if (in1 == word[0] && in2 != word[8] || in1 != word[0] && in2 == word[8]) {
printf("nOne of your answers is incorrect!n");
}
else {
printf("nTry again next time!n");
}
return 0;
}
answered Nov 21 '18 at 20:57
3D0N3D0N
12
12
add a comment |
add a comment |
Thanks for contributing an answer to Stack Overflow!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53419824%2fcomparing-characters-to-strings%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
3
You have to use logical operators like
&&
(and) or||
(or) instead of the comma operator in the conditions of yourif
-statements.– Swordfish
Nov 21 '18 at 20:17
What would be the acted upon condition in
if (in1 == word[0], in2 == word[8])
?in2 == word[8]
only?– Fiddling Bits
Nov 21 '18 at 20:18
1
@Swordfish Your comment should be an answer.
– Fiddling Bits
Nov 21 '18 at 20:18
i'm a total beginner so i was just trying my hands on it
– 3D0N
Nov 21 '18 at 20:22
@Swordfish thanks, but I would be much happier if I get a sample code of it
– 3D0N
Nov 21 '18 at 20:23