0
그래서 비교적 간단한 프로그램을 작성하여 사용자에게 명령을 추가하고 빼기 등을 묻는 메시지를 표시 한 다음 해당 작업을 완료하기 위해 숫자를 묻는 메시지를 표시합니다. 모든 것이 쓰여지고 잘 컴파일되지만 명령을 입력하면 (추가, 빼기 등) 올바르게 비교하지 못합니다. if case의 작업 분기를 입력하는 대신 잘못된 I/O catch catch로 이동합니다. 다음은 선언과 첫 번째 if 문을 포함하는 코드의 일부입니다.입력을 문자열로 비교
my $command = <STDIN>;
my $counter = 1;
#perform the add operation if the command is add
if (($command eq 'add') || ($command eq 'a')){
my $numIn = 0;
my $currentNum = 0;
#While NONE is not entered, input numbers.
while ($numIn ne 'NONE'){
if($counter == 1){
print "\nEnter the first number: ";
}else{
print "\nEnter the next number or NONE to be finished.";
}
$numIn = <STDIN>;
$currentNum = $currentNum + $numIn;
$counter++;
}
print "\nThe answer is: #currentNum \n";
#perform the subtract operation if the command is subtract
}`
내가 입력 한 내용을 추가하지 않으면 누가 알 수 있습니까?
'chomp (my $ command =);는 더 관용적입니다.) –
raina77ow
동의하지만이 경우 작은 단계가 원인과 결과를 좀 더 명확하게 만들 수 있다고 생각했습니다. –
라인에 촘촘한 추가가 완벽하게 수정되었습니다. 감사! – Bigby