绝对的初学者卡住! [英] absolute beginner stuck!

查看:59
本文介绍了绝对的初学者卡住!的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我一直在努力学习编码并选择c#开始。我正在尝试制作基于文本的游戏,但似乎卡住了。

I've been trying to learn coding and chose c# to begin with. I'm trying to make a text based game but seem stuck.

当我运行代码时,即使符合条件,也会显示错误消息。有人能解释一下我做错了吗?

when I run the code, the error message is displayed even when the conditions have been met. can someone explain what it is I'm doing wrong?

使用System;

使用System.Collections。 Generic;

使用System.Linq;

使用System.Text;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

推荐答案

您好,

 发布代码时请使用代码块,但没有说明问题所在。

 When posting code please use code blocks and you did not state what the problem was.

然而,在审查了你的代码逻辑后,问题出在

However, after reviewing your code logic, the problem is with the

 else if ( gender != "MALE" || gender != "FEMALE" )

 当评估条件时,它们被一起编辑。

 when the conditionals are evaluated they are OR ed together.

因为你正在检查Not Equal,一个True结果表示

Because you are checking for Not Equal, a True result means the

变量不是您想要的。 如果其中任何一个为True且

variable is not what you wanted.  If either are True and the

其他为False,则会得到True结果。由于OR和

other is False you get results of True. Because of the OR and the

包含括号代码,即使变量性别为

enclosing brackets code executes even when variable gender is

正确值也会执行。 尝试替换||与&&这是AND运算符。

correct value.  Try replacing the || with && which is the AND operator.

应该解决问题。

 

 希望这个帮助:)

 Hope this helps :)


这篇关于绝对的初学者卡住!的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆