Visual C++ :: How To Make Random Array To Not Repeat

Feb 17, 2013

Here is my code for a simple game. paste it and try it.

#include <iostream>
#include <string>
#include <ctime>
#include <cstdlib>
using namespace std;
int main (void) {
stringg[4],

[code]...

What they do (enter 4 actions)?

";
for (int ai = 0; ai < 4; ai++)
getline(cin, a[ai]);
cout << "

Where is happening (enter 4 locations)?

";
for (int li = 0; li < 4; li++)
getline(cin, l[li]);
for (int c = 0; c < 4; c++)
cout << g[rand() % 4] << " and " << b[rand() % 4] << " are " << a[rand() % 4] << " from a " << l[rand() % 4] << endl;
return (0);
}

At the end in the 4 lines some of the names, actions and locations repeat. How do I make them to not repeat and use every name that you will enter? do I need random_shuffle? How can I integrate it in my code?

View 1 Replies


ADVERTISEMENT

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++ :: Repeat Character Array

Nov 1, 2013

I'm having a little trouble writing program that on remove all repeat characters and leave only the non repeated characters. This is want I have so far.

#include <iostream>
#include <cstring>
#include <string>
unsigned repeatingCharCount(char const* s) {
std::string unique ;
const unsigned length = std::strlen(s) ;

[Code]...

View 6 Replies View Related

C++ :: How To Get Array To Repeat Itself After It Hits 9

Sep 13, 2013

How can I get the array to repeat itself after it hits 9?

So like this 0,1,2,3,4,5,6,7,8,9,0,1,2,3,4,5,6,7,8 and so on?

#include <iostream>
using namespace std;
int main() {
const int arraySize = 20;
int arr1[arraySize] = {0,1,2,3,4,5,6,7,8,9};

[Code] ....

View 3 Replies View Related

C++ :: Array Matrix - Extract Values Which Does Not Repeat

Jul 27, 2013

I have an array matrix called tmat,,and i know that in every row of tmax there are values which repeat two times...and am writing a code to extract the values WHICH DOES NOT REPEAT into another matrix called tcopy...the codes compiles fine...and it writes nicely to file...but without the desired result...

One last question...how can i get the array tcopy written to file in the form 5x3...and not all the figures in line one after the other? i mean i wish to see the matrix like a matrix on file..not like a list of numbers....

Code:
#include <iostream>
#include <fstream>
#include <vector>
using namespace std;
const int R = 5;
const int C = 5;

[Code] ....

View 14 Replies View Related

Visual C++ :: Unique Random Numbers In Array?

Feb 24, 2013

Below is my code for a program that is suppose to generate and display six unique random numbers (between 1 and 54). The issue seems to be in my check for duplicates. I know what I am doing wrong but can't seem to find a way to fix it. I think it is getting stuck in an endless loop because the way I have written it looks like it checks the first value against itself which will of course look like a duplicate everytime.

Code:
#include<iostream>
#include<ctime>
using namespace std;
//function prototype

[Code]....

View 1 Replies View Related

C++ :: How To Make Random Number To Be Different For X And Y

Sep 6, 2014

I got problem with the loop and Q(remains same = Q1 in output). How to make the random number to be different for x and y???

#include<stdio.h>
#include<time.h>
#include<math.h>
#include<stdlib.h>
int Random();
void Position(int z,int y);

[Code] ....

View 6 Replies View Related

C++ :: How Many Random Numbers Make Up A 100

Jun 21, 2013

Assuming you have an array of these values x=[16,18,23,24,39,40] how would you write a function to generate random numbers that can add up to a 100? I need to know how many random numbers can add up to a 100.

View 3 Replies View Related

C++ :: How To Make Random Letters With A Vector

Mar 9, 2014

I am supposed to make a scrabble game and randomize 10 of the letters.

Here's my code:
class Spinner
Spinner::Spinner(string things[], int numThings[], int n)
{
currentPosition = 0;

[Code].....

View 2 Replies View Related

C :: Two Repeat One While Loop

Apr 17, 2014

So I have a programming assignment.

Code:
#include <stdio.h>
int main(void)
{
int input;
int sum;
int i;
int t;

[Code] .....

So you input an integer ex) 30

the printing of t =(i+i)+1 and i++ is carried out until i=30, which is when the sum of all the t's is printed.

If the value you entered is not an integer, the loop ends.

I'm supposed to do this with one while loop, and no more. I can't use the for loop either.

How can I do this?

View 7 Replies View Related

C++ :: Make Program That Prints Out 10 Random Questions From 15 Questions?

Oct 29, 2013

I need to make a program that prints out 10 random questions from the 15 questions in a .txt file, and then print out the choice IN RANDOM.

View 7 Replies View Related

C++ :: Create A Loop That Repeat Itself Many Times A Second?

Aug 6, 2013

I create a loop that would repeat itself many times a second? Trying to do extremely basic graphics with a grid and system("cls") every time I run a command, but it still looks very jumpy. I realize system calls are evil. Any way to get rid of this too.

View 1 Replies View Related

C++ :: Repeat Found - Deleting In A Vector

Oct 12, 2013

I created a very basic program which contains a vector (my vector) that holds 0, 1 and 1. This program compares each element in the vector. If the element after the one currently being compared is equal to it, it outputs "repeat found!" Now this all works perfectly, but my next step was to erase the repeated one. Everything was working up until the delete step. I get a weird error that says "vector iterator not dereferencable" .

// vector::begin/end
#include <iostream>
#include <vector>
using namespace std;
int main () {
vector<int> myvector;

[Code] ....

View 6 Replies View Related

C++ :: How To Repeat For Next Word Not Exiting The Program

Sep 16, 2013

everything works it just how am i repeat for the next word not exiting the program.

// Word Jumble
// The classic word jumble game where the player can ask for a hint

#include <iostream>
#include <string>
#include <cstdlib>
#include <ctime>
using namespace std;
int main() {
enum fields {WORD, HINT, NUM_FIELDS};

[Code]...

View 1 Replies View Related

C# :: How To Repeat Execution Of Code Using Counter

Oct 22, 2014

I have a method that changes a canvas color after set intervals, e.g. start timer, 5 seconds green, 3 seconds red, then stop. This functionality is provided in the interval method. The problem I'm trying to achieve is getting this sequence to repeat for a set number of iterations.

I tried to solve this by setting up a counter after the timer is stopped but the code keeps repeating indefinitely by starting and stopping over and over instead of the max of 6 iterations I had set. In debugging the problem, I watched the value of 'i' and when the 'if' statement is set to false. The 'if' statement gets set to false after 7 iteration as expected but the start(); keeps getting called.

void myTimer_Tick(object sender, EventArgs e) {
//Assign text box string value to a time span variable.
TimeSpan workTm = TimeSpan.ParseExact(wrkString, @"hh : mm : ss : fff", CultureInfo.InvariantCulture);
TimeSpan restTm = TimeSpan.ParseExact(rstString, @"hh : mm : ss : fff", CultureInfo.InvariantCulture);

// update the textblock on the display
// with hh, mm, ss, ms
ms = myStopwatch.ElapsedMilliseconds;

[Code] .....

View 1 Replies View Related

C++ :: Structures / Loops - How Not To Repeat Typing Same Code

Jul 27, 2013

I have a structure for 4 divisions, and can't figure out how to loop through it.

So I ended up writing everything for times.

If I had 500 divisions I wouldn't be able to get away with it!

How can I have the structure in array form so I can fill it via looping?

/*Headers*/
#include <iostream>//needed 4 input/output
#include <iomanip>//needed to round
#include <string>//needed 4 strings
using namespace std;//global namespace to avoid name clash
struct division {

[code].....

View 7 Replies View Related

C :: Program That Will Repeat K Times Each Single Occurrence Of A Vowel?

Jun 8, 2014

Repeat the vowel Problem 3 (0 / 0)Write a program that will repeat k times each single occurrence of a vowel in the input file "sp.txt" to a new file "output.txt". The first line of the input file contains only the parameter k. The first line (containing the parameter k) should not to be written in the output file.

I wrote the code but i cant figure out something. i read the file, i found the vowels but then i cant print them.

Code:
#include <stdio.h>#include <string.h>
#include <ctype.h>
#define MAX 100
int checkvowel(char c)

[Code].....

View 6 Replies View Related

C :: How To Repeat A Loop Based On Number Inputted By User

Oct 21, 2014

How can i repeat a loop based on the number inputted by the user?

View 4 Replies View Related

C++ :: Repeat A Question Over And Over And Calculate Total When User Wants To Quit

Feb 27, 2014

Write a program which is used to calculate GPA based on the grades from different courses Input by the user. User should be able to enter as many course unless they choose to quit. Once the user has completed entering the data, the program should be able to provide a feedback on the GPA. Where A=4, B=3, C=2, D=1.

View 1 Replies View Related

C :: How To Make A Function Read From Array A But Put Select Parts In Array B

Jul 30, 2013

im trying to read in 1 array and get 2 as outputs from 3 different functions.my read array is easy enough were im getting confused is how to read that array, separate it and take out only the parts i want and place them into a 2nd, then again a 3rd array.i have the following so far:

Code:

#include<stdlib.h>#include<stdio.h>
#include<unistd.h>
#define SIZE 10
}

[code]....

this compiles without a complaint, but when i go to run it no longer responds after taking the 10th element (well 9th if counting from 0).I think i have the if correct for the even odd section, but when i try to populate B or C array with the output of that if statement from A is were i think things are dying...

View 12 Replies View Related

Visual C++ :: Output Of Random Numbers

Apr 6, 2015

I wrote an code for generating an aoutpu of random numbers, but it doesn't gives me back the numbers here is the code:

#include <iostream>
#include <time.h>
#include <cstdlib>
#include <stdio.h>
#include <iomanip>
#include <cmath>
using namespace std;
const int ANZ = 6;

[Code] .....

I cant find the mistake.

View 2 Replies View Related

Visual C++ :: Random Linked Strings

Feb 9, 2013

I want to make a funny and simple game in cmd with visual studio and here is my plan, here are the steps that I wanna accomplish:

The program asks the person for

1: 4 girl names
2: 4 boy names
3: What they do? (4 actions)
4: Where they do this? (4 locations)
5: Random linked things

And from here I want to randomly get 1 line of a random girl name + random boy name + random action + random place. and followed by the second, third, and fourth line of random chosen things.

Like this:
Girl 1 - Boy 3 - Action 2 - Location 4;
Girl 3 - Boy 4 - Action 4 - Location 1;
Girl 2 - Boy 1 - Action 3 - Location 3;
Girl 4 - Boy 2 - Action 1 - Location 2;

And it can get funny like: Amber and John are jumping from a bridge. a game where you can play with your friends and have fun.

Here is my code so far:

#include<iostream>
#include<string>
#include<ctime>
#include<cstdlib>
int main (void) {
using std::cin;
using std::cout;
using std::string;

[Code] ....

And from here I don't know what to do!!

View 3 Replies View Related

Visual C++ :: Random Lists Repeating

May 27, 2014

So I wanted to make a program which randomizes a list letters or something without repeating the letters like I get here:

Code:
#include <iostream>
#include <string>
#include <stdio.h> /* printf, scanf, puts, NULL */
#include <stdlib.h> /* srand, rand */
#include <time.h> /* time */
int main () {
using std::cout;
using std::cin;
using std::string;

[Code] ....

View 3 Replies View Related

Visual C++ :: Unable To Make Addon To IE

Dec 7, 2013

I am trying to make an add-on to IE. This add-on doesn't have any tool bar or any UI.

I am just taking the details of currently loaded HTML page. Basically it is for manipulating one dialog box. I want to get access to the DOM COM interfaces of the dialog box.

Since it doesn't have any button I didn't impliment IOleCommandTarget. I implemented only IObjectWithSIte.

My RGS file contain following in addition to my COM related entries

HKLM
{
NoRemove SOFTWARE
{
NoRemove Microsoft
{

[Code]...

But I couldn't see my add-on working or even not loading to IE.

View 4 Replies View Related

Visual C++ :: Can Only Make Video With 255 Frames

May 4, 2015

I have code (found long time ago, ~2001) to make videos from OpenGL rendering in my view class. In my OnDraw() function I call the function SaveAsAvi(). This works as intended until I have 255 frames in the movie I am trying to make. After that, Windows Media Player claims it cannot play the file. VirtualDub claims the avi contains Palette Changes and shows the correct number of frames (>255) but all frames past 255 are the same and equal to the last frame.

Memory overflow? Need to free m_pixels sometime somewhere?

Code:
void C***View::SaveAsAvi() {
C***Doc* pDoc = GetDocument();
if (pDoc->m_avi_status == -1)// initialize AVI stuff {
KillTimer(1);
// allocate space for the pixel info

[Code] ....

View 1 Replies View Related

Visual C++ :: Rename Files With Random Names In A Folder

May 30, 2014

I need a code for renaming multiple(bulk or all ) files in a folder.

I found one batch file script but it renaming with numbers only. But i want differntly.

[URL] .....

Example:

In a folder there are 100 images and all numbered with some digits or names.

assume that all images are belongs to "john" , so i want to rename all images with "john+ a random string".

here a random string means -> it has an array with 3000 english words, (you can predefine them by downloading from dictonary).

In the script the 3000 names are fixed, but the 1st name will be changed by my wish. that my be john, mary, sai, pavan etc...

Suggestion: you do not need to enter all 3000 words in array manually. some javscript codes are there to read input of each and evey line and them into an array.

View 2 Replies View Related







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