C++ :: Cards Game - Seeding A Vector With 52 Unique Values

Dec 29, 2013

I am trying to seed a vector with 52 values ranging from 1 to 52. I already have the code written to seed the vector bu how to keep from repeating the same values from being seeded. This is for a five card stud game.

#include<iostream>
#include<cmath>
#include<cstdlib>
#include<string>
#include<vector>
#include<ctime>
using namespace std;

[Code] ....

View 3 Replies


ADVERTISEMENT

C++ :: How To Shuffle A Vector (cards)

Mar 2, 2014

I am trying to write a sub-program that takes a deck of 52 cards and will shuffle it up using this algorithm:

Start with n=51
Repeatedly:
Generate a random integer between 0 and n. Call it i.
Swap card i and card n in the deck.
Decrease n by 1

However the code that I've written,

vector<int> shuffleDeck(vector<int> deckVector)//deckVector is the original deck in order
{
int temp, n, i, s;
n = 51;

[Code].....

when I output the new vector, only produces this output(note- it is a random number every time, but it just repeats over and over):

8 8 8 8 8 8 8 8 0 8 8 8 8 8 8 8 8 8 8 8 8 8 8 8 8 8 8 8 8 8 8 8 8 8 8 8 8 8 8 8
8 8 8 8 8 8 8 8 8 8 8 8

or:

22 22 22 22 22 22 22 22 22 22 22 22 22 22 22 22 22 22 22 22 22 22 0 22 22 22 22
22 22 22 22 22 22 22 22 22 22 22 22 22 22 22 22 22 22 22 22 22 22 22 22 22

View 1 Replies View Related

C++ :: Program - Unique Values To Use As Template Parameter

Oct 14, 2014

I'm looking for a way to generate a program-wide unique value to use as a template parameter. Generating a unique value within a translation unit is pretty easy with __LINE__, but that doesn't ensure uniqueness across translation units. I thought maybe I could use __FILE__, but that can't be used as a template parameter.

I stumbled across this page: [uRL] ....

which is exactly what I want, except that the anonymous namespace trick doesn't work on all the compilers I've tried it on. (This may be due to C++11 changing anonymous namespaces to internal linkage rather than external as they did before....that page is five years old.)

View 8 Replies View Related

C++ :: Assign Unique Integer Values For Words In Dictionary

Mar 25, 2013

I need to assign unique integer values to words in a dictionary that have the same alphabets, for example 'act' and 'cat' should have the same integer value. Would just adding the ascii values of the letters be sufficient?

View 1 Replies View Related

C Sharp :: How To Loop Through Array List For Unique Values

Aug 19, 2012

I am grabbing data from three entities and want to grab a field value in each of the entites and place it in an arraylist. What I would like to do is loop through the arraylist for all the values and do something for each value only once. If the value in the array list is repeated, I want to not do anything for it and continue till the end. Basically, I loop through all the values do something for each value and skip over the repeated value if I already did something.

View 1 Replies View Related

C++ :: Recursive Function - Creating Vector Of Every Unique Combination Of Commands

Mar 24, 2013

I'm trying to write a recursive function that takes in a vector of strings that contains

"1 forward", "2 forward", "rotate left", "2 backwards" ... etc

how can I write recursive function that creates a vector of every unique combination of commands?

View 8 Replies View Related

C++ :: Create Array Of Playing Cards / Assign Values And Suits Then Shuffle The Array

Nov 24, 2014

I got this program to create an array of playing cards and assign the values and suits and shuffle the array. I'm at the point where I need to output the cards but I need to burn the first card by making it output "**" instead of the card. my cards[] is a constant so I can's assign the first card as such.

void showCards(const int cards[], int numCards, bool hideFirstCard) {
if (cards[0]) {
hideFirstCard=true;
cards[0] = '**';
} for(int a = 0; a <= numCards; a++) {
cout >> showCard(cards[a]);
} }

View 1 Replies View Related

C++ :: Write A Program That Replaces Values In A Vector With Their Absolute Values

Dec 4, 2013

This is my code: [tag]

Code:
#include <iostream>
#include <string>
#include <cstring>
#include <vector>

using namespace std;

[Code] .....

View 4 Replies View Related

C++ :: Two Player Tic Tac Toe Game - Use Enums When Possible To Represent Values

Apr 19, 2013

Here is the code I have written so far. My problem is that when the second user enters its position the last user's position is wiped of the board. I want to know how I can hold that position and keep doing so until the game is finished. I thought that calling the previous function would do that (and you can see where I have put that into a comment) but it doesn't.

Code:
#include <iostream> //includes header file
using namespace std;
//function prototypes
void printLeftUpper(int i, int j);
void printMiddleUpper(int i, int j);

[Code] ....

View 1 Replies View Related

C :: Binary Game - Using Values With Some Basic Logical Operations

Apr 24, 2014

When things at work get overwhelming, it's not unusual for me to briefly "escape" by writing small programs simply for fun. A few days ago, I had an idea for a "binary game". I completed the first draft of it yesterday.

The idea is simple. The game uses 8-bit values. At the start of the game, a random "target" value is generated. The player is dealt a "hand" of seven values. The object is to use the values in your hand, along with some basic logical operations, to create the "target" value. While the idea is simple, the game itself can be quite difficult.

Here is an example of the output:

Code: --------------------
T: 1111 1100 (0xFC)
--------------------
0: 0000 0000 (0x00)
--------------------
1: 1100 1110 (0xCE)
2: 1010 0011 (0xA3)
3: 1100 0101 (0xC5)
4: 1011 1111 (0xBF)
5: 1010 1011 (0xAB)
6: 0001 1011 (0x1B)
7: 0001 1011 (0x1B)
--------------------

: Looking at the first column:
- 'T' is the "target" value
- '0' can be thought of as the "game board" - this is the value that needs to match the target value for a win
- '1' - '7' are the values in your "hand"

You can apply logic AND ('A'), OR ('O'), or XOR ('X') to a value in your hand with the value on the "game board". You are also allowed to apply logic to two values in your hand to create a new value for your hand. When a value from your hand is used, it is removed.

Some examples of the commands:

A30 --- apply logic AND to value #3 in your hand, and the "game board" value
O23 --- apply logic OR to value #2 in your hand and value #3 in your hand
X70 --- apply logic XOR to value #7 in your hand, and the "game board" value

You can also be dealt new values (as long as there's room in your hand) with the '+' command. 'H' or 'h' prints the help, and 'Q' or 'q' exits the game.

I haven't thoroughly tested it yet, since I just finished it a yesterday, but so far it looks good. The program itself uses only standard C.

I was dickering with the idea of supporting more logical operators (NOT, NAND, NOR, XNOR, shift), but I like the simplicity and resulting difficulty of the current implementation.

During initial testing, I realized it's possible to have doubles in your hand. Also, it's quite possible to be dealt the target value directly, which means that you could potentially win with one move, chance permitting. At first I thought about defending against these conditions, but came to the conclusion that it is fine as is - chances of an instant win are small, and if it does occur, would still be an enjoyable experience. Besides, if you're dealt the target value after the "game board" value has been modified.

Also, I did not allow a value of "zero" in the players hand. This was originally because I thought it would be of little use (though I've been reconsidering this). This also means that if two values in the hand are combined and result in zero, both values are removed and no new value is added. This was originally a bug, but I think I'll just reclassify it as a feature

So far, I found that the best strategy is to avoid modifying the "game board" value, and just play with the values in your hand. If you can get the target value in your hand, you just OR it with the "game board" and you're done.

View 2 Replies View Related

C++ :: Dice Game - Receive Same Values When Roll Function Get Call Twice For Same Object

Nov 7, 2013

#include <iostream>
#include <cstdlib>
#include <time.h>
#include <conio.h>
using namespace std;
class Dice {

[Code] ....

Every time the roll_dice function get call twice for the same object, i receive the same dice values.

View 4 Replies View Related

C/C++ :: Madd Libs Game - How To Store Inputted Strings Or Values To Arrays

Nov 11, 2014

My assignment is writing Madd Libs game. I still do not understand how to store inputted strings or values to arrays. I need explanation of collecting inputted data to arrays.

#include "stdafx.h"
#include<stdio.h>
//#include<string.h>
int main(void) {
char string[37] = {''};
char adjective1[15];

[Code] ....

View 14 Replies View Related

C++ :: Subtracting Values In A Vector?

Jun 9, 2013

I want to add this piece of code to a project. I have created a vector from values entered by a user. I want to then subtract each value from each other from the beginning to the end. For example if a user enters 10,4,3 the program will subtract the values in that order 10 - 4 - 3 and output 3 as the solution. I figured how to do it with addition but can't get it to output for subtraction.

#include <iostream>
#include <vector>
using namespace std;

[Code].....

View 5 Replies View Related

C++ :: Printing Vector Values Preceded By

Apr 17, 2014

Why does this generate an error:

Code: std::copy( vec.begin( ) , vec.end( ) , std::ostream_iterator<double>( " " , std::cout ) ); whereas this works fine:
Code: std::copy( vec.begin( ) , vec.end( ) , std::ostream_iterator<double>( std::cout , " " ) ); I know I can use this instead:
Code: for ( std::vector<double>::iterator it1 = vec.begin( ); it1 != vec.end( ); ++it1 ) std::cout << " " << *it1;

View 5 Replies View Related

C++ :: Assigning List Of Values To Vector?

Mar 30, 2013

I am trying to assign a list of values to a vector:

vector<string> words;
words[] = {"one", "two", "three"};

This does not work. How can I accomplish it?

View 5 Replies View Related

C++ :: Erase Multiple Values In A Vector

Mar 17, 2014

I wud like to delete multiple values from a vector using indexes as my values r not fixed they may change so using indexes i want to delete

For example: vector<int> v={1,2,3,4,5};

I want to erase 3,4,0 indexes

So resulting vector is 2,3

View 6 Replies View Related

C++ :: Print Values From A Vector Of A Struct?

Apr 5, 2013

I'm trying to print values from a vector of a struct and I don't really know how to do that. Here is a simple code that I have for now to test how to add data to the vector then attempt to print it out.

#include <iostream>
#include <vector>
#include <string>
#include <deque>
#include <fstream>
using namespace std;
struct Employee//employee data

[Code]...

View 2 Replies View Related

C++ :: Can't Store Different Values Into Vector By User Input

May 4, 2013

I can`t seem to store multiple values into my vector when a user keys in an input. Lets say a user inputs 1,2 as the first set and later keys in 3,4.

My vector gets overridden by 3 and 4. I'm trying to pass these values into a function to store them into a vector and use them in the function.

Below is my code snippet

int reconstructSecret(int x, int y) {
int getX,getY;
getX=x;
getY=y;
vector<int> myXCordVec;
vector<int> myYCordVec;

[Code] .....

View 6 Replies View Related

C/C++ :: Vector Of Class Outputting Garbage Values

Jun 21, 2014

I have a class that uses std::vector. I push back class objects onto the vector but when I try to cout the data members (with get functions) I get garbage values.

Here is the class:

#ifndef JOBS_H
#define JOBS_H
#include <iostream>
#include <iomanip>
#include <vector>
#include <string>
using namespace std;
class Jobs{

[Code] ....

I know I am missing the implementation of several functions but I'm just testing my vector to see if it is working and it isn't. The getBlockValue() function should output 0 for each job. When I push back one object the output is 0. When I push back 2 objects the output is 0. However when I push back 3 objects I get random values. Why is this? I thought vectors were dynamic?

View 8 Replies View Related

Visual C++ :: Assigning Values To And Extracting Them From A Vector

Nov 28, 2012

I am writing a program to play rock paper scissors, and I am trying to get a vector to store the result of a given round of play, and output it as a declaration as to who won. I can't figure out how to store the values in the vector properly, and how to use the vector as an argument to output the result of play.

Code:
#include <iostream>
#include <iomanip>
#include <ctime>
#include <vector>
#include <cstdlib>
#include <string>
using namespace std;
const string name[4] = {" ", "rock", "paper", "scissors"};
const string roundResult[3] = {"computer win", "player win", "tie"};

[Code]....

View 1 Replies View Related

C++ :: Method Passes Values To A Vector But It Stays Empty?

Dec 10, 2014

I have two classes, one class requests another class to populate a vector with some data using getAvailableStreams() method:

vector<AutoRefPtr<ManifestStream> > availableStreams;
std::cout << "now asking for streams." << std::endl;
manifest->getAvailableStreams(&availableStreams);
std::cout << "got so many streams: " << availableStreams.size() << std::endl;

The other class passes another pre-populated vector back:

virtual RESULT getAvailableStreams(std::vector< AutoRefPtr<ManifestStream> >* availableStreams) {
availableStreams = static_cast<std::vector< AutoRefPtr<ManifestStream> >* >(myStreams); //myStreams contains 1 stream

I'm also adding a stream here directly just for testing purposes:

ManifestStream stream2;
availableStreams->push_back(AutoRefPtr<ManifestStream>(&stream2));
std::cout << "calling getAvailableStreams. Giving so many streams: " << myStreams->size() << ", " <<
availableStreams->size() << std::endl;
return result_OK;
}

If I run the code, I can see the following logs:

Now asking for streams. Calling getAvailableStreams.
Giving so many streams: 2, 2
got so many streams: 0

Why am I getting 0 streams when I exist the method? I just had 2 streams in availableStreams while I was inside the method, where have they disappeared?

View 6 Replies View Related

C++ :: Incrementing Values In Vector Based On Variable Input

Mar 24, 2014

I'm trying to increment the values in a vector, not the vector size, based on variable input. Basically I have a vector of size 10, and all of its values are initialized at zero. The program counts the frequency of numbers 0-9 in a four digit user input. This is what I have (I want it to work so badly but the compiler says that I'm using a pointer to a function used in arithmetic):

for (int i=0; i < num_slots; ++i) {
++guess_frequency[guess[i]];
}

I just want to know if you can increment values within a vector:

E.g.
change
0 0 0 0 0 0 0 0 0 0
to
1 0 0 0 2 0 0 1 0 0

View 6 Replies View Related

C++ :: Rotates A Vector 90 Degrees - Values Won't Stay Negative

Jan 21, 2015

I have a function that rotates a vector 90 degrees. Only problem is, i never get negative values. For some strange reason, no matter what i do, the value of x is positive. And even if the x is negative. Once i put it into direction (struct with 2 values x and y) it turns again to positive. Im using VSC++2013 ultimate. At first direction was SDL_Point, so i thought it was SDL problem, but now it seems its something else.

if (c == '-') {
int x = direction.y;
x *= -1;
int y = direction.x;
direction = { x, y };
}

View 8 Replies View Related

C++ :: Program To Read Series Of Comma Delimited Values From A File Into Vector

Aug 12, 2012

I'm trying to get my program to read a series of comma delimited values from a file into a vector. However, I am unsure how to actually go about doing this. I've posted my best guess below but it's really just a stab in the dark and I always receive a compiler error.

Code:

#include <iostream>
#include <fstream>
#include <vector>
#include <string>
using namespace std;
vector <string> v_input;
int main() {
ofstream fout ("Insert File Path Here.txt");
fout << "4, 8, 15, 16, 23, 42";

[Code] ....

View 3 Replies View Related

C++ :: Deck Of Cards - No Output

Mar 5, 2013

I'm still new at C++, so my syntax might be a little off for getting the correct output. Currently, there are no compiler errors or warnings, but there is also no output when I run the program. It seems as if it is not calling something correctly maybe the .toString or perhaps my DeckOfCards constructor is a little off, either way, I can't seem to figure out why there is no output.

Anyways, here is my code:

Card.h
#ifndef CARD_H
#define CARD_H
#include <string>
using namespace std;
class Card {

[Code] ....

View 3 Replies View Related

C++ :: How To Fill Cards In Deck

Sep 9, 2013

Here is my source code i am trying to write a function (fillAll) to fill all 52 cards in a deck and i would like to use my data struct for the function and make Deck one of my parameters.

enum suit{HEARTS, CLUBS, DIAMONDS, SPADES};
enum face{TWO, THREE, FOUR, FIVE, SIX, SEVEN, EIGHT, NINE, TEN, JACK, QUEEN, KING, ACE};
struct Card{
suit suitType;
face faceType;

[Code] .....

View 10 Replies View Related







Copyrights 2005-15 www.BigResource.com, All rights reserved