Return Styles: Pseud0ch, Terminal, Valhalla, NES, Geocities, Blue Moon. Entire thread

guessing a-z

Name: Mattew 2007-01-26 2:49

hey, i could use a little help with this code for C++. I have been at it for several hours now and being a fresh new programmer to C++. I was wondering if someone could give me some help or sutocode for this game.

And here is the rand() code that I have:
// ASCII code for lower case a-z.
char randChoice = rand() % 25 + 98;

Write a game that picks a random letter between ‘a’ and ‘z’ (the lowercase alphabet). Read a character (and the newline that must follow it) and tell the user how many letters away they are. Repeat until they guess the right one.

Name: 1 2007-01-26 17:31

Thanks >>3, your wise. Here's what I ended up with


my @words;
push @words, $_ foreach a..z;

while (1) {
        print "Guess: ";
        chomp(my $guess = <STDIN>);
        if ($guess eq $words[int rand @words]) {
                print "You guessed right!\n";
        }
        else {
                print "Try harder.\n";
        }
}

Newer Posts
Don't change these.
Name: Email:
Entire Thread Thread List