well i'm trying to get my shuffler to work but i keep getting one. any ideas?

#include <cstdlib>
#include <string>
#include <ctime>
#include <iostream>

 using namespace std;

 const int number_of_cards = 52;

void shuffle(int list[], int size)
{
    srand(time(0));
    for (int i = 0; i < size; i++)
    {
        int index = rand() % number_of_cards;
        int temp = list[i];
        list[i] = list[index];
        list[index] = temp;
        }

}

int main()
{
    int deck[number_of_cards];
    const string suits[] = {"Clubs", "Diamonds", "Hearts", "Spades"};
    const string ranks[] = {"Ace", "2", "3", "4", "5", "6", "7", "8", "9", "10", "Jack" "Queen", "King"};
    int value[]={1,2,3,4,5,6,7,8,9,10,10,10,10};
    int i = 0;
    for(i = 0; i < number_of_cards; i++)
        deck[i] = i;

    shuffle(deck, number_of_cards);

    cout << value[deck[i]%13];


    getchar();
    return 0;
}

well im trying to get my shuffler to work but i keep getting one. any ideas?

You keep getting one? What do you mean? I ran your code and it produces a seemingly random string of numbers when I display the entire array like this:

for (int i = 0; i < 52; i++)
    cout << deck[i] << endl;

Yes but i want a random number out of the int value array.

for (int i = 0; i < 52; i++)
cout << value[deck%13] << endl;

i used this and i got the values of my cards. Any ideas on were to go from here? i realy dont know what im doing.

for (int i = 0; i < 52; i++)
cout << value[deck%13] << endl;

i used this and i got the values of my cards. Any ideas on were to go from here? i realy dont know what im doing.

Your thread is marked "Solved". Is that on purpose? I'm not sure what you are trying to do. You have a card shuffling function that, at first glance, appears to work. I have a very similar snippet here.

It's not clear to me what the goal is or what the problem is. You are trying to draw a single card from a random location in the shuffled deck? Is that it?

Im trying to make a war game. I need to split a randomized deck in half. Then compare values from from 1 to 13. and so on

i guess now i need to learn how to split the array in half and compare the values of the user to the value of the computer.

It will be easier to help you if you can be a little more detailed in your questions. Your deck shuffler function seems to work. If you are trying to split the array, first decide on some function parameters. For example, you could do this:

void SplitDeck (int fullDeck[], int firstHalfDeck[], int secondHalfDeck[])

You can then split the deck into two in a variety of ways (first 26 cards go in first half, second 26 cards go in second half, or you can go every other card, or whatever). If the deck is not cut EXACTLY in half, you can specify another parameter:

void SplitDeck (int fullDeck[], int firstHalfDeck[], int secondHalfDeck[], int numCardsInFirstHalf)

This program is going to take some organization, so think about how to organize it first, then figure out exactly what functions you need, then start programming.

Well this is for a class. My teacher said we could either make a card game. or make code for a vending machine that we already have object oriented. Which one do you think would be easier?

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

struct items
{
       int price;
       int invent ;
       string name;
} invent[25];

int filein(struct items invent[], int coins[],int &i);
int fileout(struct items invent[], int coins[]);
void coin_input(int coins[],int &t);

int main()
{

    int coins[3] = {0},t =0,i=1,j=1,x=1;

    filein(invent, coins,i);


    i -=1;
    while (x != i)
    {
        cout <<"\n" <<x<<". "<< invent[x].name <<"\n    there are "<<invent[x].invent <<"\n    the price is $0."<<invent[x].price;
        x++;
    }    
    cout << "\n\nWhat item do you want? ";
    cin >> x;
    coin_input(coins, t);


    while (j != 0)
    {
          if (invent[x].invent = 0)
          {
          cout << "no more in stock!";
          j=0;
          } 
          else if (invent[x].price <= t)
          {
             t -= invent[x].price;
             cout <<" the gave you 1 "<< invent[x].name;
             invent[x].invent--;
             j = 0;

          }
          else
          {
              cout << "you need more Money! if want " << invent[x].name << " you need $0." << invent[x].price << " and you have " << t << "\nTo put more money in = 1, (if not = 0)";
              cin >> j;
              coin_input(coins, t);
          }
    }

    fileout(invent, coins);

   cout << "\n";
   system("PAUSE");
    return 0;
}










int filein(struct items invent[], int coins[],int &i)
{
     i=0;
     int g=0;
     ifstream fin ("itemlist.txt") ;

     if (! fin)     // Always test file open
     {
           cout << "Error opening output file" << endl;
           return -1;
           getchar();
           getchar();
     }
   fin >> g;
    while (i <=g)
    {

              fin >> invent[i].name;
              fin >> invent[i].invent;
              fin >> invent[i].price;
              i++;


    }    

     fin.close();


     ifstream fin1 ("coins.txt");

     if (! fin1)     // Always test file open
     {
           cout << "Error opening output file" << endl;
           return -1;
           getchar();
           getchar();
    }

          fin1 >> coins[0];
          fin1 >> coins[1];
          fin1 >> coins[2];
          fin1 >> coins[3];

    fin1.close();
 return 0;
}

int fileout(struct items invent[], int coins[])
{
     int i=0;
ofstream fout ("itemlist.txt") ;

if (!fout)     // Always test file open
   {
   cout << "Error opening output file" << endl;
    return -1;
    getchar();
    getchar();
    }

    while (!fout.eof())
    {
          //if (!fout.eof())
          //{
              fout << invent[i].name << endl;
              fout << invent[i].invent << endl;
              fout << invent[i].price << endl;
              i++;
          //}
    }    

    fout.close();

    ofstream fout1 ("coins.txt") ;

if (! fout1)     // Always test file open
   {
   cout << "Error opening output file" << endl;
    return -1;
    getchar();
    getchar();
    }

    fout1 << coins[0]<< endl;
    fout1 << coins[1]<< endl;
    fout1 << coins[2]<< endl;
    fout1 << coins[3]<< endl;

    fout1.close();

 return 0;
}




 void coin_input(int coins[],int &t)
 {
      int quarters = 0, dimes = 0, nickels= 0, dollars = 0;
      cout << " Enter the number of dollars: ";
      cin >> dollars;

      dollars += 100;
      cout << " Enter a number of quarters: ";
    cin >> quarters;
    coins[1] += quarters;
    quarters=quarters*25;
    cout << " Enter a number of dimes: ";
    cin >> dimes;
    coins[2] +=dimes;
    dimes *= 10;
    cout << " Enter a number of nickels: ";
    cin >> nickels;
    coins[3] +=nickels;
    nickels *=5;

   t += nickels + dimes + quarters + dollars;
}

 void coin_output(int coins[],int &t)
{
int dollars = 0, oneDollars = 0,cQuarters = 0,cDimes = 0, cNickekls = 0, NewTotal = t;



    while (NewTotal != 0)

{
    if (NewTotal > 99)
       {
       NewTotal -= 100;
       dollars++;
       }
    else if(NewTotal >= 25)
        {
        cQuarters++;
        NewTotal -= 25;
        }
    else if(NewTotal >= 10)
    {
       cDimes++;
       NewTotal -= 10;
    }
    else if(NewTotal >= 5)
    {
       cNickekls++;
       NewTotal -=5;
    }
}    

    cout << "\n";
cout << "You got:\n";
cout << "\n";



    if (oneDollars >0)
{
    cout << oneDollars;
    cout << " One Dollars bills.\n";
}

if (cQuarters >0)
{
    cout << cQuarters;
    cout << " Quarters.\n";
}   

if (cDimes >0)
{
    cout << cDimes;
    cout << " Dimes.\n";
}   

if (cNickekls >0)
{
    cout << cNickekls;
    cout << " Nickels.\n";
}   



}

plz help

Don't be impatient, if you want fast help you should give a detailed and understandable description of what your problem is first :)

sorry im just stressed beyond belief, gotta be at work in 2 hours this program is due tomrow night. And the whole time my dad is being a dick.

How would i split value[deck%13]; into 2 separate arrays

sorry im just stressed beyond belief, gotta be at work in 2 hours this program is due tomrow night. And the whole time my dad is being a d---.

Well, we've all been there. I have to leave, but I have time for another post. Here would be my approach. These assignments almost always have very strict criteria. Your professor very likely provided you a detailed list of things the program must have, as well as things that are optional. Start with that. Generally professors don't say "Make a war game or a vending machine program", particularly in lower-division courses. They usually give detailed parameters. As far as which to do, I don't know, but pick one and stick with it. If it was me, with the disclaimer that I haven't seen the actual assignment specification, I would do the vending machine since it seems more straight-forward. The program will likely be longer, but it'll be easier to design. Again, look at the spec and see what's REQUIRED. A vending machine could be extremely basic or it could be extremely involved (i.e. inventory, the ability to change prices, keep track of the amount of purchases, make change, etc.). Do what's required first, and nothing more. Then if you feel like it, add options. Almost certainly there will be a menu. What's in the menu depends on what the program's options are. At the very least, it'll probably have something like:

1. Buy a drink.
2. Exit

Then you'll have submenus like:

1. Coke 55 cents
2. Sprite 60 cents
3. Dr. Pepper 75 cents

It's impossible to be more specific in the advice since like I said, it all depends on the spec and how you choose to approach it. But I'd go for the vending machine probably.

I think im stuck with the card game because i know nothing about object orientation yet. He didnt give any requirements whatsoever he just said any card game. He didnt Say anything about how it was done.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.