我刚开始学习稳健,我试着签一个合同,你可以把名字添加到圣诞老人的淘气或美好的名单中,我想要输入一个名字,我希望输出是在淘气的还是好的名单上,还是不存在。在这里,我试图查看输入的名称是否在“淘气”列表中,它给了我错误消息:未声明的标识符。我在最后一个函数中突出显示的位置出现了这个错误,谢谢任何帮助我的人。
pragma solidity ^0.8.11;
contract SantaList {
struct NaughtyList{
string badBoy;
uint position;
}
struct NiceList{
string goodBoy;
uint position;
}
NaughtyList[] public badNames;
NiceList[] public goodNames;
uint internal nextPosition = 1;
function AddToBadList(string memory badBoy) public{
badNames.push(NaughtyList(badBoy, nextPosition));
nextPosition++;
}
function AddToNiceList(string memory goodBoy) public{
goodNames.push(NiceList(goodBoy, nextPosition));
nextPosition++;
}
function GetNaughtyList() view public returns(NaughtyList[] memory){
return badNames;
}
function GetNiceList() view public returns(NiceList[] memory){
return goodNames;
}
function CheckList(string memory name) public {
for(uint i = 0; i < badNames.length; i++){
if(badNames[i].badBoy == **badBoy**){
return **badBoy**;
return " is on the naughty list";
}
}
}
}发布于 2021-12-29 22:23:33
如果要检查badNames中是否有名称
function CheckList(string memory name) public view returns (string memory) {
for(uint i = 0; i < badNames.length; i++){
if(badNames[i].badBoy == name){
return string(abi.encodePacked(name, " is on the naughty list"));
}
}
return string(abi.encodePacked(name, " is not on the naughty list"));
}https://ethereum.stackexchange.com/questions/117408
复制相似问题