Enter a group of test scores


 
Thread Tools Search this Thread
Top Forums UNIX for Dummies Questions & Answers Enter a group of test scores
# 1  
Old 05-28-2010
MySQL Enter a group of test scores

I'm trying to write a shellSmilie script that would calculate my class average from exams. Ineed to calculate the lowest and the highest scores as well overall average.
# 2  
Old 05-28-2010
You definitely should post how your input file looks like (it does not have to be your real data, you can post sample data, but the structure should be the same as your original file), otherwise no one can know how it looks like, hence we cannot provide you appropriate code.
Don't forget to use the code tags Smilie
# 3  
Old 05-29-2010
Well being a newbie I hope I am doing some thing right. Here is what I am trying to do. I want to prompt the user to enter a group of test scores. Then calculate the lowest and highest overall average.Then put on the screen the three items lowest, highest, overall average and total number of scores supplied. Ask if any more to process. If so perform the operation again. If not exit. I am using a copy of ubuntu to write script and I am using 0 to 100 on test scores. The last person to help me gave me a script in Perl and I thank him for that. I need a script to run with command line on Ubuntu. Lenix I think.

Last edited by rcbrown; 06-02-2010 at 12:06 PM.. Reason: the perl script I got is over my head
# 4  
Old 05-30-2010
All right, this is what I have done so far, but I'm still not sure if it will act like you wanted, because I simply don't know how your scores look like. Also this script has a very restrictive regular expression, which will prevent you from submitting it garbage. This means only integers and certain floating point numbers will be accepted, hope it will suffice. Besides I hope you know how to run Perl scripts Smilie

checkscore.pl
Code:
#!/usr/bin/perl

use strict;
use warnings;

my (@arr, $tot, $cont);

sub get_score
 {
  print "score OR r for result OR q to quit: ";

  my $choice = <STDIN>; chomp($choice);

  if ($choice eq "r")
   {
    my $totelements = @arr;
      if ($totelements >= 2)
       {
	@arr=sort{$a<=>$b}(@arr);

 	foreach my $number (@arr)
	{
        $tot += $number;
        }
        my $avg = $tot / $totelements;

 	print "\n  LOWEST: $arr[0]";
 	print "\n HIGHEST: $arr[-1]";
 	print "\n AVERAGE: $avg";
 	print "\n  SCORES: $totelements\n\n";

   	print "Press ENTER to continue...";
   	$cont = <STDIN>;
   	again();
       }
       else
       {
 	print "Need at least 2 valid scores. Reset. Try again.\n\n";
 	@arr=(); $tot=0;  get_score();
       }

   }
   if ($choice eq "q") { exit(); }
   if ($choice =~ /^\d+(\.\d+)?$/) {
   push @arr, $choice;
   } else { print "Invalid input!\n\n"; }
   get_score(); 
 }

sub again {

   print "\nRun again? (y/n) ";
   $cont=<STDIN>;
   chomp ($cont);
   @arr=(); $tot=0; get_score() if $cont eq "y";
   exit() if $cont eq "n";
   again();

}

sub exit { exit; }

get_score();


Test run / Script demonstration:
Code:
$ ./checkscore.pl
score OR r for result OR q to quit: .13
Invalid input!

score OR r for result OR q to quit: 12.
Invalid input!

score OR r for result OR q to quit: 
Invalid input!

score OR r for result OR q to quit: 10
score OR r for result OR q to quit: r
Need at least 2 valid scores. Reset. Try again.

score OR r for result OR q to quit: 100
score OR r for result OR q to quit: 25
score OR r for result OR q to quit: 66
score OR r for result OR q to quit: 87
score OR r for result OR q to quit: 10
score OR r for result OR q to quit: 45
score OR r for result OR q to quit: 6
score OR r for result OR q to quit: r

  LOWEST: 6
 HIGHEST: 100
 AVERAGE: 48.4285714285714
  SCORES: 7

Press ENTER to continue...

Run again? (y/n) y
score OR r for result OR q to quit: 1.3
score OR r for result OR q to quit: 4.7
score OR r for result OR q to quit: 0.2
score OR r for result OR q to quit: r

  LOWEST: 0.2
 HIGHEST: 4.7
 AVERAGE: 2.06666666666667
  SCORES: 3

Press ENTER to continue...

Run again? (y/n) n
$


Last edited by pseudocoder; 06-01-2010 at 02:19 PM..
This User Gave Thanks to pseudocoder For This Post:
 
Login or Register to Ask a Question

Previous Thread | Next Thread

8 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Create combinations based on scores

Hi experts, I have a score matrix like below, where the 3rd column ( 1 max, 0 min) says how close the 2nd column variable is to the 1st column variable a b 0.3 a c 0.87 a d 0.75 b x 0.67 b y 0.98 b z 0.24 c ... (4 Replies)
Discussion started by: jianp83
4 Replies

2. Shell Programming and Scripting

Loop logic, enter into respective IF as per enter input file name

have three big data file, however I just need to see the mentioned below one line form the all the file which has SERVER_CONNECTION Value File 1 export SERVER_CONNECTION=//dvlna002:10001/SmartServer File2 export SERVER_CONNECTION=///SmartServer File3 export... (1 Reply)
Discussion started by: Nsharma3006
1 Replies

3. Shell Programming and Scripting

Calculating the average of scores

Hi I have 2 files file1 aac 23 25 aac 87 90 aac 33 67 file2 23 0.9 24 0.8 25 0.4 ........ 67 0.55 ........ I want to get output as (11 Replies)
Discussion started by: anurupa777
11 Replies

4. Shell Programming and Scripting

Selecting sequences based on scores

I have two files with thousands of sequences of different lengths. infile1 contains the actual sequences and infile2 the scores for each A, T, G and C in infile1. Something like this: infile1: >HZVJKYI01ECH5R TTGATGTGCCAGCTGCCGTTGGTGTGCCAA >HZVJKYI01AQWJ8 GGATATGATGATGAACTGGTTTGGCACACC... (4 Replies)
Discussion started by: Xterra
4 Replies

5. UNIX for Dummies Questions & Answers

Group of test scores

Well being a newbie I am hope I am doing the right thing. Here is what I am trying to do. I want to prompt the user to enter a group of test scores. Then calculate the lowest and the highest overall average. Then put on the screen the three items lowest highest overall average and total number of... (3 Replies)
Discussion started by: rcbrown
3 Replies

6. Shell Programming and Scripting

How to check weather a string is like test* or test* ot *test* in if condition

How to check weather a string is like test* or test* ot *test* in if condition (5 Replies)
Discussion started by: johnjerome
5 Replies

7. Shell Programming and Scripting

Test on string containing spacewhile test 1 -eq 1 do read a $a if test $a = quitC then break fi d

This is the code: while test 1 -eq 1 do read a $a if test $a = stop then break fi done I read a command on every loop an execute it. I check if the string equals the word stop to end the loop,but it say that I gave too many arguments to test. For example echo hello. Now the... (1 Reply)
Discussion started by: Max89
1 Replies

8. Post Here to Contact Site Administrators and Moderators

My game scores are not recording

Hi. I scored 38 on the hex game and it would not record my score. Strange. (2 Replies)
Discussion started by: MokoMoko
2 Replies
Login or Register to Ask a Question