PDA

View Full Version : Your Logic.



bullet2urbrain
01-30-2007, 06:19 PM
K, well i got an assignment from my C++ prof. ( IM TERRIBLE AT PROGRAMMING)

we had to code a program that scores a blackjack hand. Not deal or shuffle or anything, just prompt the user to input their cards and then give them back a score.

so we have the following facts.

Min cards = 2
Max cards = 5

and Aces can be 1 or 11
Face cards = 10

you must continue to score hands until user does not wish to continue

what methodology would you use?

feel free to use words..no code.

like i tried to do it as

A switch, using switch on the # of cards they have. then asking for their cards, and using the logic that if score > 21 aces were 1.

koensa
01-31-2007, 02:11 AM
give a bit more info plz

how does the user input a card? just he typs 1 and then enter?
of more like "Ace spades"

i'm sure you best way to work is with an array
in wich you can predefine an value to another name

and loopt that until the user presses something like K or S (to stop inputting)

bullet2urbrain
02-01-2007, 09:51 AM
You are making it way to complicated, they user must simply input the number of cards they have, then input the cards they actually have, then you program must output what their score is (best case)

i ended up using a whole lot of "If else if else" logic (14 of them) to do everything.

I got a 9 out of 10 on the assignment, saying that my 2 errors were that under one condition my "ace" logic didnt work, and that my program could have been made shorter.

nn_step
02-01-2007, 09:02 PM
input card, then have it prompt if you need to input another card.
Check to see if the # of entered cards is greater than 5, if so then prompt error and continue to processing, else check to see if atleast count is greater than or equal to 2. If it is less than, then another card must be inputted, else continue

bullet2urbrain
02-02-2007, 07:38 AM
thats actually really wise NN.

Its unfortunate that it was already due, that could have reduced the amount of code i needed to write.

Thanks for the input.. I will add to this thread at a later date with our next HW.

Which is reading in from 2 different files and merging them into one output file. using File I/O

nn_step
02-02-2007, 08:53 AM
thats actually really wise NN.

Its unfortunate that it was already due, that could have reduced the amount of code i needed to write.

Thanks for the input.. I will add to this thread at a later date with our next HW.

Which is reading in from 2 different files and merging them into one output file. using File I/O
:shakes: if you instructor doesn't tell you that the code is ugly and bloated, give me his phone number and I'll give him a talking to.

bullet2urbrain
02-02-2007, 09:23 AM
:shakes: if you instructor doesn't tell you that the code is ugly and bloated, give me his phone number and I'll give him a talking to.

He loves Fortran and Cobol still... he's too stuck in being a Coder and not out in the real world at all....

His Idol is Admiral Grace Hopper... if that says anything.

nn_step
02-02-2007, 11:07 AM
He loves Fortran and Cobol still... he's too stuck in being a Coder and not out in the real world at all....

His Idol is Admiral Grace Hopper... if that says anything.
it is one thing to love programming and another to love Cobol