School Assignment? Project Due Tomorrow? Chat LIVE With A Programming Expert!

Welcome to Dream.In.Code
Become an Expert!

Join 300,489 Programmers for FREE! Get instant access to thousands of experts, tutorials, code snippets, and more! There are 1,819 people online right now. Registration is fast and FREE... Join Now!




Help with Input

 

Help with Input, TextPad won't accept any input

krich87

8 Jun, 2009 - 02:42 PM
Post #1

New D.I.C Head
*

Joined: 3 Dec, 2008
Posts: 31



Thanked: 1 times
My Contributions
I am coding in the dark due to the fact that I have Perl linked to textPad and every time I execute my code it only displays the print lines. It will not accept any input, textPad simply tells me "This is a read only document". So none of my STDIN's are working. I think that all my code works and fulfills all these requirements but can someone help me out

These are the requirements
Project 1
Create a program for printing lottery tickets

The program must have these features
1) Print a welcome screen
2) Ask the user for the # of tickets desired (1 thru 10)
3) Ask the user how many numbers on a ticket (e.g. 6)
4) Ask the user for the maximum of the number (e.g. 44)
5) Generate the #s using a random number generator
6) Print the lottery #s in a user friendly way
7) Thank the user for using your program.

The program must be user friendly and prompt the user for re-entering the input if there is an error in the input e.g. # of tickets > 10

The lottery numbers for a ticket must be unique though they can be repeated in other tickets.

CODE

#!/usr/bin/perl

$counter = 0;

print "Welcome to the lottery program!\n";
print "How many tickets would you like to purchase? (1 - 10): ";
chomp($tickets=<STDIN>);
print "\n";
print "\n";

do
{
    if ($tickets > 10)
    {
        print "To many tickets, purchase 10 or fewer...";
        chomp($tickets=<STDIN>);
    }
}
while ($tickets > 10);

print "How many numbers will be on each of your tickets? ";
chomp($numbers=<STDIN>);
print "\n";
print "\n";

print "What is the maximum number for each ticket? ";
chomp($maximum=<STDIN>);
print "\n";
print "\n";

print "These are your lottery tickets\n";
do
{
    my @numbers = (1..$maximum);
    my $limit = $numbers;
    my %list = ();
    while (keys %list < $limit)
    {
        $list{$numbers[rand @numbers]}=1;
    }
    print join(' ', sort {$a <=> $b} keys %list);
    print "\n";
    $counter++;
}
while ($counter < $tickets);

print "\n";
print "\n";

print "The winning combination of lottery numbers is...";
my @numbers = (1..$maximum);
my $limit = $numbers;
my %list = ();
while (keys %list < $limit)
    {
    $list{$numbers[rand @numbers]}=1;
    }
print join(' ', sort {$a <=> $b} keys %list);

print "\n";
print "Thank you for using the lottery program!\n";



User is offlineProfile CardPM
+Quote Post


krich87

RE: Help With Input

8 Jun, 2009 - 05:44 PM
Post #2

New D.I.C Head
*

Joined: 3 Dec, 2008
Posts: 31



Thanked: 1 times
My Contributions
This stupid thing still isn't working, maybe I have some setting messed up or something...

Does anyone have any suggestions?

I have the latest version of ActivePerl free from Activestate.
I linked it to textPad using this process:
Configure > Preferences > Tools > Add > Program > (Find Perl) > Apply
Then I made sure only the capture output checkpox was selected, clicked apply one more time then hit OK...

And it isn't working!!
User is offlineProfile CardPM
+Quote Post

KevinADC

RE: Help With Input

8 Jun, 2009 - 07:02 PM
Post #3

D.I.C Regular
Group Icon

Joined: 23 Jan, 2007
Posts: 401



Thanked: 25 times
Dream Kudos: 50
My Contributions
How are you trying to run the program? If you have perl associated with textpad then textpad will just open the perl file for editing, no? To run your terminal based scripts on Windows with perl you open a command (or DOS) Window. Type:

c:\>perl path\to\your\scriptname.pl

then press enter. If perl is not in the command path, and assuming default install of activeperl:

c:\>perl\bin\perl.exe path\to\your\scriptname.pl

This post has been edited by KevinADC: 8 Jun, 2009 - 07:03 PM
User is offlineProfile CardPM
+Quote Post

KevinADC

RE: Help With Input

8 Jun, 2009 - 07:08 PM
Post #4

D.I.C Regular
Group Icon

Joined: 23 Jan, 2007
Posts: 401



Thanked: 25 times
Dream Kudos: 50
My Contributions
By the way, your program almost works. It does run and prompts for input but the output doesn't seem quite right. Here was a run, my input is in square brackets []:


Welcome to the lottery program!
How many tickets would you like to purchase? (1 - 10): [5]

How many numbers will be on each of your tickets? [3]

What is the maximum number for each ticket? [49]

These are your lottery tickets
1 38 40


The winning combination of lottery numbers is...20 32 45
Thank you for using the lottery program!


User is offlineProfile CardPM
+Quote Post

n00bc0der

RE: Help With Input

9 Jun, 2009 - 06:02 AM
Post #5

D.I.C Head
**

Joined: 27 Nov, 2008
Posts: 62



Thanked: 3 times
My Contributions
I may be way off here, but it may have to do with file permissions/executable rights. Just a shot in the dark.
User is offlineProfile CardPM
+Quote Post

Fast ReplyReply to this topicStart new topic

Time is now: 11/8/09 04:16AM

Live Help!

Be Social

Dream.In.Code RSS Feed Dream.In.Code LinkedIn Group Follow Us On Twitter Fan Us On Facebook

Tutorials

Programming

Web Development

Reference Sheets

Code Snippets

DIC Chatroom

Bye Bye Ads

Monthly Drawing

Thumb Drive

Top Contributors

Top 10 Kudos This Month