GIDForums  

Go Back   GIDForums > Computer Programming Forums > C++ Forum
User Name
Password
Register FAQ Members List Calendar Search Today's Posts Mark Forums Read
 
 
Thread Tools Search this Thread Rate Thread
  #1  
Old 17-Feb-2012, 21:24
jham92 jham92 is offline
New Member
 
Join Date: Feb 2012
Posts: 1
jham92 is on a distinguished road

High card evaluator


I am creating a program in c++ that has the user enter 4 cards and I need it to display the high card any help or advice would be great thanks
  #2  
Old 18-Feb-2012, 06:52
davekw7x davekw7x is offline
Outstanding Member
 
Join Date: Feb 2004
Location: Left Coast, USA
Posts: 6,153
davekw7x is a splendid one to beholddavekw7x is a splendid one to beholddavekw7x is a splendid one to beholddavekw7x is a splendid one to beholddavekw7x is a splendid one to beholddavekw7x is a splendid one to beholddavekw7x is a splendid one to beholddavekw7x is a splendid one to behold

Re: High card evaluator


Quote:
Originally Posted by jham92
...advice...
Ya gotta have a plan. Sometimes I start with some pseudo-code that describes the action. (But: See Footnote.)

Here's a possibility:

Suppose we have some scheme by which the user can enter a card name (a string). The program will have a way of assigning a value (a positive integer) to a card with a valid name.

Note that there must be a way of validating the card name. The validation functionality can be implemented as a separate function or can be made part of the code that assigns the numerical value.

Code:
Declare a signed integer variable named highCardValue, and set its value to -1. (We will have defined things so that no actual card will have a value less than or equal to zero). Declare a string, highCardName. (It is initially an empty string.) Then... Go through the following loop until the required number of card names has been obtained from the user BEGIN LOOP Prompt user to enter a card. Declare a string variable named cardName and get the cardName from the user. IF the name is valid THEN IF the numerical value of this card is greater than the current highCardValue, then set the value of highCardvalue to this card's value, and set highCardName to this card's name. END LOOP Print out highCardName.


Regards,

Dave

Footnote:
This is a very general expression of a plan. Maybe it's too much. Maybe it's not enough.

For example, if you don't need to keep track of the suit, maybe you just need to get a rank from the user (1 through 13, or one of the set {2, 3,...10, J, Q, K, A}.

If you have to keep track of suits, there is the question of whether all cards of the same rank have the same value. (Does the ace of spades have a higher value than the ace of clubs, for example.) If suits are irrelevant, then you may need to consider what to do if two cards of equal value are drawn. In fact, it's not clear whether the four cards "drawn" by the program are necessarily distinct.

Once we start thinking about things, then the following "issues" arise:

Are the cards "drawn" from a deck? How many cards are in the deck?

Is a card replaced in the deck after being drawn? Or what?

Is the program required to keep track of all cards drawn (so that it can check for duplicates)? Or what?


See what I did here? I started writing code (pseudo-code in this case) before I actually had a program specification. I don't think it was necessarily wasted effort, but I think that writing a program specification should precede writing code. In this case (since we don't know what your actual assignment is), I just threw out some things in the pseudo code that can act as a template for the actual program. Details may be added (or removed), depending on the program specification.

So: The real bottom line (before you write the plan) is to describe, exactly, what the user input is required to be and what you should do with the input to get the output.
__________________
Sometimes I just can't help myself...
Last edited by davekw7x : 18-Feb-2012 at 07:22.
 


Thread Tools Search this Thread
Search this Thread:

Advanced Search
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
Credit Card Processing For High, Domestic Bank Backed HughH1 eCommerce / Merchant Account Forum 0 07-Feb-2012 17:26
Learning Java - Need Tips LocalTech Java Forum 5 11-Aug-2011 07:56
Sound card driver setup swazi Computer Hardware Forum 4 04-Sep-2004 09:27
6 Parties for Every Credit Card Transaction Corey Bryant eCommerce / Merchant Account Forum 0 16-Aug-2004 15:28
Card Game Help! Pravda C++ Forum 4 28-May-2004 08:40

Network Sites: GIDNetwork · GIDApp · GIDBlog · Learning Journal by J de Silva, The

All times are GMT -6. The time now is 04:40.


vBulletin, Copyright © 2000 - 2014, Jelsoft Enterprises Ltd.