我的编程和逻辑入门课程的最终实验将不会执行,它在屏幕上快速闪烁CMD,然后什么也没有发生。我不确定这是语法错误还是什么。非常感谢您的帮助。
#Part 2 Insert 1.0
@username=(“first”,“last”);
print "Please enter your first name: ";
$username[0] = <STDIN>;
chomp $username[0];
print "Please enter your last name: ";
$username[1] = <STDIN>;
chomp $username[1];
print "Your name is:\n";
print "$username[0]\n$username[1]\n";
print "Please enter a number\n";
$number1 = <STDIN>;
chomp $number1;
#Part 2 Insert 1.0 - END
print "Please enter a second number\n";
$number2 = <STDIN>;
chomp $number2;
while ( $number2 == 0 )
{
print "You entered $number2\nPlease enter a non-zero number\n";
$number2 = <STDIN>;
chomp $number2;
}
print "Please enter your first name\n";
$name=<STDIN>;
chomp $name;
print "$name, how many times do you want to run your program?\n";
$total_loops=<STDIN>;
chomp $total_loops;
print "\n$name, you entered $number1 and $number2\n";
for($ctr=1; $ctr <= $total_loops; $ctr++)
{
print("\nDisplaying $ctr of $total_loops loops \n\n");
print("Please make a selection using the menu below\n");
print "1 - Subtract \n";
print "2 - Divide\n";
print "3 - Modulus\n";
print "4 - Exit\n";
$answer = <STDIN>;
chomp $answer;
#next line edited to use lab4 part 2 array
print "$username[0] $username[1] You selected $answer as your menu choice\n\n";
if($answer == 1)
{
$sub = $number1 - $number2;
print("$number1 - $number2 is $sub");
}
elsif($answer == 2)
{
$quot = $number1/$number2;
print "$number1 / $number2 is $quot";
}
elsif($answer == 3)
{
$mod=$number1 % $number2;
print "$number1 % $number2 is $mod";
}
elsif($answer == 4)
{
print "Exiting program";
exit 0;
}
else
{
print "$answer is not a valid menu choice! Please retry.";
}
print ("\n"); #blank line
}
预期- 提示输入名称并分配给数组 提示输入数字 操作选择菜单 从数组中打印具有指定名称的结果
实际-快速CMD窗口闪烁然后什么也没有
答案 0 :(得分:3)
这听起来像是您在某种目录列表中双击该程序,该程序在命令窗口中启动该程序,然后立即将其关闭-没有时间让您看到它显示的消息。解决方案一定是打开您自己的命令窗口,然后在提示符下键入perl your_program_name.pl
。程序退出时,已经打开的命令窗口不会关闭,您将能够看到错误。
(但是,如果我不得不猜测,我建议问题出在定义@username
的那一行中的“智能引号”。)