-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathassign1.plx
78 lines (55 loc) · 1.09 KB
/
assign1.plx
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
#!/usr/bin/perl
use warnings;
use strict;
#creating array
my %test=qw(Test0 0 Test1 0 Test2 0 Test3 0 Test4 0);
my %quizzes;
my $answer;
my @arrayHolder;
my $counter=0;
my $element;
my $alltestelements=0;
my $allquizelements=0;
#prompting user
print "Press '1' to enter tests and '2' to enter quizzes";
#grabbing input
$answer = <STDIN>;
#checking input
if($answer == "1")
{
print "Enter 5 space seperated test grades \n";
#asking and getting scores
$answer=<STDIN>;
#splitting input by spaces
@arrayHolder=split /\s+/, $answer;
#looping through
for $element(@arrayHolder)
{
$test{"Test" . $counter}=$element;
++$counter;
}
#doing math
for (keys %test)
{
$alltestelements=$alltestelements+$test{$_};
}
$alltestelements=$alltestelements/5;
print $alltestelements;
}
if($answer == "2")
{
print "Enter 5 space seperated test grades \n";
$answer=<STDIN>;
@arrayHolder=split /\s+/, $answer;
for $element(@arrayHolder)
{
$test{"Test" . $counter}=$element;
++$counter;
}
for (keys %test)
{
$allquizelements=$allquizelements+$test{$_};
}
$allquizelements=$allquizelements/5);
print $allquizelements;
}