C/C++ :: Shuffle Songs Into Random Order

Sep 26, 2014

What's wrong with my shuffle function? It shuffles some songs, yet completely gets rid of others.

Here's the code:

void shuffle() //Shuffles songs into a random order. {
Music temp, temp2; //Temporary music file holders, 'Music' is a struct with string title;, string artist;, and int size;.
unsigned int currentTime = (unsigned)time(0);
srand(currentTime);
for (int i = 0; i < NUM_SONGS; i++)

[Code] .....

I want it to output this:

1. Title: Runaway2, Artist: Bon Jovi2, 2 MB
2. Title: Runaway5, Artist: Bon Jovi5, 5 MB
3. Title: Runaway1, Artist: Bon Jovi1, 2 MB
4. Title: Runaway4, Artist: Bon Jovi4, 1 MB
5. Title: Runaway7, Artist: Bon Jovi7, 5 MB
6. Title: Runaway6, Artist: Bon Jovi6, 5 MB
7. Title: Runaway3, Artist: Bon Jovi3, 5 MB
8. Title: Runaway8, Artist: Bon Jovi8, 1 MB

Or something along those lines, but instead I get something like this:

1. Title: Runaway7, Artist: Bon Jovi7, 1 MB
2. Title: Runaway2, Artist: Bon Jovi2, 2 MB
3. Title: Empty, Artist: Empty, 1856312448 MB
4. Title: Runaway4, Artist: Bon Jovi4, 1 MB
5. Title: Runaway5, Artist: Bon Jovi5, 5 MB
6. Title: Empty, Artist: Empty, 0 MB
7. Title: Runaway7, Artist: Bon Jovi7, 1 MB
8. Title: Empty, Artist: Empty, 1856312448 MB

View 2 Replies


ADVERTISEMENT

C++ :: Stalk Random Alpha Letter In Order

Nov 3, 2013

How to stalk a random alpha letter in order in a minimum possible way.. and write the cases which the container can be stalked.

for example.. ACMICPC can be a store in three stalks.

ACC
M -----------> three stalks
IP

Another example... CBACBACBACBACBA can have three stalks

View 12 Replies View Related

C++ :: Output Sections Of Txt Code In Random Order

Mar 27, 2014

I will keep this simple as I have the code written for my testing software program, I just want to add a feature of randomly generating the answer choice output order, I do not want to randomly output the full questions, but instead the choices (answers to the question), for example =

#include <string>
#include <iostream>
#include <limits>
cout <<" " << endl ; \ space

[Code] ....

As you can see I would like to output the answers, choices randomly as in answer choice 3 will appear at the top instead of 1. and so on, it doesn't matter if the numbers move with the txt as the numbers beside the
questions are txt.

It's a 32bit console application.

View 4 Replies View Related

C/C++ :: Compare Two Arrays And Print Out A List Of All Songs Without Repeating

Mar 11, 2014

I have two arrays:

const char *mymp3list[15] = { "Song 1", "Song 2", "Song 3", "Song 4", "Song 5", "Song 6", "Song 7", "Song 8", "Song 9", "Song 10", "Song 11", "Song 12", "Song 13", "Song 14", "Song 15" };
const char *myFriendsmp3list[20] = { "Song 1", "Song 2", "Song 3", "Song 4", "Song 5", "Song 6", "Song 7", "Song 8", "Song 9", "Song 10", "Song 11", "Song 12", "Song 13", "Song 14", "Song 15", "Song 16", "Song 17", "Song 18", "Song 19", "Song 20"};

And I want to compare the two arrays and print out a list of all the "songs" without repeating any.

I've figured out how to print the just the duplicates using:

for (int count = 0; count < SIZE1; count++){
for (int i = 0; i < SIZE2; i++){
if (mysonglist[count] == friendsonglist[i])
cout << mysonglist[count] << "";
}
}

But I'm stumped on how to print a full list containing no duplicates.

View 4 Replies View Related

C++ :: Sorting User Defined Amount Of Random Numbers In Ascending Order

Jan 30, 2013

I want to implement a function into the code below that sorts the user defined amount of random numbers and then sorts them in ascending order.

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

using namespace std;
class IntegerArray {

[Code] ....

View 5 Replies View Related

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 :: 2D Array With 108 Strings - Shuffle Function?

Sep 7, 2013

I have a 2D array with 108 strings. How do I shuffle it correctly?

Code:
void Shuffle( char dest[208][13] )
{
// Initialize variables
char temp[13];

// Loop and shuffle(swap array values)

[Code] .....

The program force closes.

View 6 Replies View Related

C++ :: How To Shuffle A Word Coming From A File

Sep 24, 2013

HOW TO SHUFFLE A WORD COMING FROM A FILE?

FILE *DOCU;
DOCU = fopen ("file.txt", "r");
if (DOCU == 0) {
printf ("
Failed to open!

[Code] .....

View 4 Replies View Related

C++ :: Member Function To Shuffle Content?

Nov 14, 2014

Is there member functions for STL's like vector,list etc., to shuffle the content of that STL.

eg:

int arr[] = {1,2,3,4};
std::vector<int> v1(arr, arr+ sizeof(arr) / sizeof(int) );

now i need to shuffle the data randomly like

Now vector may contain {3,2,4,1} or {2,1,4,3} ...

I have taken vector as an example. let me know if there is any alternative way with other STL's

View 2 Replies View Related

C :: How To Shuffle Bits Of Plain Text According To DES Standard

Jul 14, 2014

I learned the bitwise operations in c, but how to shuffle the bits of the plain text accoring to DES's standard. Even with the key and the S-boxes. How DES is performed in C step by step. I have a fair knowledge in C.

View 3 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++ :: Make 10 Random Numbers Thus Making 10 Random Flips Of Coin?

Aug 31, 2013

I want to make 10 random numbers thus making 10 random flips of a coin. I am getting 10 tails or 10 heads!

Code: #include <iostream>
#include <ctime>
#include <cstdlib>
using namespace std;
int main(int argc, const char * argv[])
{

[Code].....

View 4 Replies View Related

C++ :: Random Value At Random Time?

Dec 30, 2013

my motive is to get random variable at every start of program.so it does not show same sequence when it run again and again

int main()
{
srand( time ( NULL ) );
cout<<rand();
}

when i run this program in code::block the following program is opening with error in new tab called TIME.H

/*
* time.h
* This file has no copyright assigned and is placed in the Public Domain.
* This file is a part of the mingw-runtime package.
* No warranty is given; refer to the file DISCLAIMER within the package.
*
* Date and time functions and types.
*
*/
#ifndef_TIME_H_
#define_TIME_H_

[Code]....

View 5 Replies View Related

C++ :: Why Are Random Values Not Very Random

Nov 26, 2014

I've been working on a little experiment, here is the source: [URL]

The problem that I keep running into is when I run the initPop and generate an individual object, the genome of the next individual is _exactly_ the same as the previous one... which confuses me... Shouldn't each individual be randomly different from the one that preceded it? What am I not right when it comes to generating random values?

View 8 Replies View Related

C :: Array Out Of Order Function

Dec 4, 2013

I want to write a function that can accept any arbitrary array of doubles and return the index of the first element that is out of order or -1 if the elements are in order. Why my for loop exists immediately after an element is found to be out of order. What is wrong with my code and why?

Code:
int out_of_order(double stuff[], int size)
{
int i;
//run through entire array

[Code]....

View 2 Replies View Related

C++ :: How To Get Numbers In Order But Not Changing Name It Goes With

Mar 13, 2014

SO lets say I have a file that says

10 tennent
9 Eccleston
12 Capaldi
11 Smith

How do I get the number's in order but not changing the name it goes with? SO here is how I started it

# include <iostream>
# include <fstream>
# include <sstream>
# include <set>
# include <list>
# include <string>
# include <cctype>
# include <vector>

[Code] ....

View 12 Replies View Related

C++ :: Does Order Of Declaration Matter

Jul 25, 2013

I have recently found this article: URL.....In their example, by declaring variables in other order, they saved 8 bytes. However, shouldn't compiler take care of it? Is it true, and should I declare variables more carefully?

View 3 Replies View Related

C++ :: Randomizing Order Of If-else Statements

Dec 11, 2013

The purpose of doing this is so that the top of the if statements is not preferred over the bottom. I tried assigning enum values to each case. Then choose a random integer r from 0 to the size of the std::list myList containing those enum elements. The enum value is found using it = std::next (myList, r). Then if the if statement corresponding to that enum value is false, then myList.erase (it), and repeat the process with the newly reduce myList. It works, and everything seems nicely randomized. But it is disappointing much slower than when I used the original if-else statements (it is being applied hundreds of times).

Here is a snippet of my code (I decided not to use switch statements because it looked too clumsy):

std::list<FacingDirection> guyFacingDirections = {Positive_x, Negative_x, Positive_y, Negative_y, Positive_xPositive_y, Positive_xNegative_y, Negative_xPositive_y, Negative_xNegative_y};
while (true) {
const int r = rand() % guyFacingDirections.size();

[Code] .....

There is a crowd of girls. Each guy will choose a girl, and then choose a facing direction to dance with his chosen girl. But not all facing directions are possible if someone is standing at the spot he wants to stand at to get his desired facing direction. Without randomizing the if-else statements, most of the guys will end up facing the same direction, which I don't like.

View 18 Replies View Related

C++ :: DLL Search Directory Order

Aug 29, 2013

I was working on a program. "hey if this program were to be published it would be bad for people to see all dll files are in the exe directory"....

So I wondered if there is a way to make compiler see a folder in the same directory with exe file which holds all dll files?

Also look at some programs and saw they have a dll folder which holds dll files....

View 1 Replies View Related

C/C++ :: Bubblesort In Ascending Order?

Apr 21, 2014

I am trying to build a c++ that reads user input and arrange letters in ascending order. for example, if the user input: Hello my name is Moe! the output will be: !aeeehillmmmnoos (ascending order)

my problem is that when i input hello my name is moe the output will be ehllo (not completing other letters) also when i change class size to 50, it outputs unknown weird letters.

This is my code:

#define CLASS_SIZE 10
#include <stdio.h>
#include <iostream>

[Code].....

View 2 Replies View Related

C# :: Output Numbers In Different Order?

Mar 17, 2015

I am currently writing a program and am having some trouble figuring out how to get the order correct in the output.

Here is my code:

using System;
using System.Collections;
using System.Text;
namespace The_Last_Survivor {
class Program {
static void Main(string[] args) {

[code].....

The output I need to have is:

Actors Count Audition Order

1 1 1

2 1 1 2
2 2 2 1

3 1 1 2 3
3 2 2 1 3
3 3 3 1 2

4 1 1 2 3 4
4 2 2 4 3 1
4 3 3 2 4 1

[code].....

Right now the numbers are just printing in order 1-9 and not changing.

View 7 Replies View Related

C# :: How To Order A Dynamic List

Nov 11, 2014

I have to following:

List<string> keyList = new List<string>();
keyList = data.First().Keys.ToList();

I also have a table with a column called display_order which i need to use in the order by

I have tried:

keyList = data.OrderBy(s => s.).ToList();
keyList = data.First().OrderBy(keyList).ToList();
orderBy = "Display_Order asc";
keyList = data.First().OrderBy(orderBy).ToList();
keyList = data.First().OrderBy().ToList();
keyList = data.First().OrderBy(keyList.display_order).ToList();

Am I missing something?

View 4 Replies View Related

C# :: Sort In Ascending Order?

Mar 10, 2015

i have a list

ID | Location | Quantity
1 | 2 | 5
2 | 3 | 10
3 | 4 | 8

i want the order to be in ascending order by Quantity so it should produce this

ID | Location | Quantity
1 | 2 | 5
3 | 4 | 8
2 | 3 | 10

View 4 Replies View Related

C++ :: Singleton Destruction Order

May 28, 2012

I've been upkeeping a mess of a code recently, that uses "pseudo" singletons. Basically, the current code has "Initialize_All" static functions that initializes all the singletons in a given order. At the end of the program, we call "Destroy_All", and destroy everything in the reverse order.

The code is actually heavilly dll'ed, and Initilize_All and Destory_All are referenced counted. We ask that any client who uses our code call Initialize_All first and then Destroy_All when they are finished. The first Initilize_All will initialize everything, and the last Destory_All will delete everything.

This is showing its limits.

I'd like to move us to a fully singleton design. The singleton pattern means we don't have to use an Initilize_All, and each singleton can manage construction dependencies by itself (we are mono-threaded).

Each singleton is "clean", so it is cleans itself up at dll destruction.

The big question is this one:

If there is a singleton dependency during destruction, eg: ~A requires an instance of singleton B (which is in another DLL), are we guaranteed proper behavior?

Or, is there an "Static de-initialization order fiasco"?

If yes, are there any design that can combat this fiasco, short of having each singleton register itself in a manager, that will destroy them in reverse order?

View 6 Replies View Related

C++ :: How To Declare High Order Vectors

Sep 21, 2013

I suspect that C++11 would make it possible to declare high rank vectors such as Code: int N = 15; // chosen arbitrary rank vector<vector<vector<...<vector<double>>>>..> vec; // N layers of nested vectors Is there a way to declare such a vector of rank N (given a fixed integer rank N)?

Heuristically I would like to write the declaration like this: Code:

vector<double> A;
vector<A> vec[0];
for(int i=1; i<N; i++)
{
vector<vec[i-1]> vec[i];
} Is there a way to use the new variadic templates to make this work?

View 9 Replies View Related

C++ :: Initialize A Variable In Order To Run Loop At Least Once

Apr 4, 2013

I've been messing around with loops/functions and basic logic and come up with a small maths program. Here it is:

Code: #include <iostream>
#include <string>
float divide (float x, float y) //function to divide numbers {
return x / y;

[Code] ....

Would initializing the string 'anotherGo' to a value that makes the loop run at least once be a suitable way of doing this rather than using a do/while loop? I read that a do/while loop is a black sheep but I have come across a number of uses for it. Maybe it is just preference which one you should/could use?

View 9 Replies View Related







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