- #1
franznietzsche
- 1,504
- 6
I wrote an (small) AI script for twenty questions in perl, however i need the code translated into C++ (i ahve some knowledge of C++, but not enough to write this program). Thanx for the help:
Code:
#!/usr/bin/perl
use warnings;
$ans = 0;
$qnumber = 1;
while (($ans == 0)&& ($qnumber < 20)) {
print "Ask a question: \n";
$_ = <STDIN>;
if (/end/ && /vowel/ && (/everything/ || /anything/)){
print "You got it right!\n";
$ans = 1;
} elsif (/a$/ or /e$/ or /i$/ or /o$/ or /u$/ or /a\?$/ or /e\?$/ or /i\?$/ or /o\?$/ or /u\?$/ ) {
print "Yes\n";
} else {
print "No\n";
}
$qnumber ++ ;
if ($qnumber == 20){
print "You've run out of questions. Better luck next time!\n";
}
}