Difference between revisions of "Exercise 6.3"

From Earlham CS Department
Jump to navigation Jump to search
 
Line 1: Line 1:
 
Return to [[Week 3]]
 
Return to [[Week 3]]
Exercise 6.3 in <i>Beginning Perl for Bioinformatics</i></b>
+
Exercise 6.3 in <i>Beginning Perl for Bioinformatics</i>
  
 
<pre>
 
<pre>

Latest revision as of 19:30, 30 September 2009

Return to Week 3 Exercise 6.3 in Beginning Perl for Bioinformatics

#!/usr/bin/perl
use warnings;
use strict;

#Erika Phelps
#28 Sept 2009
#Exercise 6.3

#Pseudocode:
#Design a main program that is kind of like a madlib.
#Use a subroutine to return the user's word.

#Main body:
#Tell the user s/he is playing silly madlibs.
#Ask the user to input a word.
#Construct a short story and insert each of the returned value somewhere

##Subroutine
#Ask the user for a random word.
#Collect the answer.
#Return the answer.

#******PROGRAM BEGINS HERE*****

#Define variables

my $word = 0;
my $message = "Please enter a noun: ";

#Introduce the program

print "Hello! Play a madlibs game with me! \n";

$word = userprompt($message);

print "I think you look like a $word! HAHA!\n";

print "Would you like to play again?\n";


exit;

#Can make more interesting by using If statement to ask to play again.


############
#Subroutine#
############

sub userprompt {

    my $message = @_;

    print "@_";

    my $word = <STDIN>;

    chomp $word;

    return $word;
}