Welcome to Dream.In.Code
Getting C++ Help is Easy!

Join 136,122 C++ Programmers for FREE! Get instant access to thousands of C++ experts, tutorials, code snippets, and more! There are 1,769 people online right now. Registration is fast and FREE... Join Now!




adding total

 
Reply to this topicStart new topic

adding total, help plz

noob2007
14 May, 2007 - 04:15 AM
Post #1

New D.I.C Head
*

Joined: 3 Apr, 2007
Posts: 38


My Contributions
OK.below is my code involving random numbers. now i need to get teh scoring system to work.
these are teh criteria:

Each hand has card points calculated
according to
o J (Jack) has 1 point
o Q (Queen) has 2 points
o K (King) has 3 points
o A (Ace) has 4 points

so this means wen a jack or queen or king or ace appears, it calculates it i.e. if a jack then score is 1 and a queen appears tehn scores are 1 + 2 = 3. therefore score is 3 and so on.

the thing is i dont kno how to code it so tat wen a J or Q or K or A appears it calculates accordingly.



CODE
#include <iostream>
#include <cstdlib>
#include <ctime>
using namespace std;

int main()
{
    const int card = 13;
    const int suit = 4;
    const int player = 4;
    char *cards[] = {"2", "3", "4", "5", "6", "7", "8", "9", "10", "J", "Q", "K", "A"};
    char *suits[] = {"S", "C", "D", "H"};
    int i, num, num1, players, numofplayers, points;
    int total = 0;
    
    srand(time(NULL));
    
    cout << "Note: S is Spades, C is Clubs, H is Hearts and D is Diamonds\n\n";

              cout << "Player 1\n";
              for (int i = 0; i < 13; i++)
              {
                num = rand() % 13;
                num1 = rand() % 4;
                cout << cards[num] <<  " of " << "[" << suits[num1] << "]" << ", ";
              }
              cout << "\nTotal Points: ";
              cout << "\n-------------------------------------------";

              


This post has been edited by noob2007: 14 May, 2007 - 04:17 AM
User is offlineProfile CardPM
+Quote Post

AmitTheInfinity
RE: Adding Total
14 May, 2007 - 04:58 AM
Post #2

C Surfing ∞
Group Icon

Joined: 25 Jan, 2007
Posts: 1,025



Thanked: 35 times
Dream Kudos: 125
My Contributions
Your "num" variable can do that for you. If it goes beyond 8 then it is either of J, Q, K or A.

just check this condition everytime and if it becomes true, break out of the loop and do your calculation.
User is online!Profile CardPM
+Quote Post

Reply to this topicStart new topic
Time is now: 12/1/08 10:10PM

Live C++ Help!

C++ Tutorials

Reference Sheets

C++ Snippets

DIC Chatroom

Bye Bye Ads

Monthly Drawing

Thumb Drive

Top Contributors

Top 10 Kudos This Month