Created
March 12, 2013 18:27
-
-
Save seyDoggy/5145518 to your computer and use it in GitHub Desktop.
Billy Goat Restaurant solution.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/php -q | |
<?php | |
/* | |
Problem Solving and Programming Concepts | |
Adam Merrifield (2697795). | |
Billy Goat Fast Food | |
PSEUDO CODE | |
start | |
Declarations | |
string msgQty = "Enter quantity for next item (q to Quit): " | |
string msgSelect = "Enter item: " | |
int userQty = prompt("Please enter item quantity (q to Quit): ") | |
string userSelect | |
string product[3] = 'cheeseburger', 'pepsi', 'chips' | |
double price[3] = 2.49, 1.00, 0.59 | |
int quantity[3] = 0, 0, 0 | |
int noProduct = 1 | |
if userQty <= 0 | |
output "Your order was empty." | |
else | |
while userQty != 'q' && userQty > 0 | |
userSelect = prompt(msgSelect) | |
noProduct = 1; | |
for i=0, i < count(product), i++ | |
if userSelect == product[i] | |
quantity[i] += userQty | |
output "You ordered userQty userSelect." | |
else | |
noProduct++ | |
endif | |
endfor | |
if noProduct > count(product) | |
output "We don't have any userSelect."; | |
} | |
userQty = prompt(msgQty) | |
endwhile | |
tally(priceTable) | |
endif | |
end | |
tally(prod, pri, qty) | |
int tally = 0 | |
output "Your total order is" | |
for i=0, i < count(prod), i++ | |
if qty[i] > 0 | |
output "qty[i] prod[i] at pri[i] = pri[i] * qty[i]" | |
tally += pri[i] * qty[i] | |
endif | |
endfor | |
output "Your total cost is tally" | |
output "Thank you for visiting the Billy Goat Fast Food Restaurant." | |
void | |
prompt(message = null) { | |
output message | |
input = STDIN | |
return | |
*/ | |
/** | |
* Actual running program | |
*/ | |
(string)$msgQty = "Enter quantity for next item (q to Quit): "; | |
(string)$msgSelect = "Enter item: "; | |
(int)$userQty = prompt("Please enter item quantity (q to Quit): "); | |
(string)$userSelect = 0; | |
(array)$product = array('cheeseburger','pepsi', 'chips'); | |
(array)$price = array(2.49, 1.00, 0.59); | |
(array)$quantity = array(0, 0, 0); | |
(int)$noProduct = 1; | |
if ($userQty <= 0) { | |
echo "Your order was empty.\n"; | |
} else { | |
while ($userQty != 'q' && $userQty > 0) { | |
$userSelect = prompt($msgSelect); | |
$noProduct = 1; | |
for ($i=0; $i < count($product); $i++) { | |
if ($userSelect == $product[$i]) { | |
$quantity[$i] += $userQty; | |
echo "You ordered " . $userQty . " " . $userSelect . ".\n"; | |
} else { | |
$noProduct++; | |
} | |
} | |
if ($noProduct > count($product)) { | |
echo "We don't have any " . $userSelect . ".\n"; | |
} | |
$userQty = prompt($msgQty); | |
} | |
tally($product, $price, $quantity); | |
} | |
function tally($prod, $pri, $qty) | |
{ | |
(int)$tally = 0; | |
echo "Your total order is\n"; | |
for ($i=0; $i < count($prod); $i++) { | |
if ($qty[$i] > 0) { | |
echo $qty[$i] . " " . $prod[$i] . " at $" . number_format($pri[$i], 2, '.', '') . " = $" . number_format($pri[$i] * $qty[$i], 2, '.', '') . "\n"; | |
$tally += $pri[$i] * $qty[$i]; | |
} | |
} | |
echo "Your total cost is $" . number_format($tally, 2, '.', '') . "\n"; | |
echo "Thank you for visiting the Billy Goat Fast Food Restaurant.\n"; | |
} | |
function prompt($message = null) | |
{ | |
fwrite(STDOUT, $message); | |
$input = trim(fgets(STDIN)); | |
return $input; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment