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
ADVERTISEMENT
Sep 20, 2014
Inside my loop is this
srand(time(NULL))
a=rand()%10;
So it will generate numbers again and again as the loop goes on but it always repeat some numbers. My question is, how would you generate numbers without repeating? Somebody told me that i have to use auto increment, but i really have no idea about that.
View 8 Replies
View Related
Sep 8, 2014
I have been given an assignment to make a code to read some text nd display all the words nd the number of times they appear in another file or as output without displaying the repeating words. I made the code but its not giving any output.
#include<iostream>
#include<conio.h>
#include<fstream>
#include<string>
using namespace std;
void read(string);
string x,z,w;
[Code] ....
View 3 Replies
View Related
Mar 12, 2013
Im working on a script compiler and i need to handle different types of data. Actually different categories of items.
Let's say i have two categories: cat's and bird's. They are different and stored in different lists. And let's say there is a simple command: GIVE_FOOD_TO(animal_type, food_type) Animal type here can be either from birds category or cat's category.
And also let's say user gives command: GIVE_FOOD_TO(cat1, fish)
and also for example: GIVE_FOOD_TO(bird1, birdfood)
Variable names could be anything, but im storing each variable name in std::map so later i can figure out with what animal current command is used.
When im parsing the script then i must know if user supplied either cat or bird. If i just would have cat's or bird's category then i would have only 2 lists and not a big problem to loop through either cats list or birds list and find out in what list the "cat1" is or in what particular list the "bird1" is. It would be in one or another.
But i have a lot of categories and looping through all of these lists (or std::maps) is slow and doesn't seem like a good. Just to find out in what list it's stored. I can't rely on variable names, they could be anything.
Big picture atm:
1) I have one BIG box which stores all of the categories
2) When i need to find out to which category the variable (animal_type) point's to i must get it quickly, dunno, std::map in std::map or something?
What i need basically is: I have different lists (each one is just a category for either birds or cats in this example) And when i have variable name, i must find out quickly in what particular category this item is stored. So i can work with it.
View 4 Replies
View Related
Jul 8, 2014
Well I've given myself a lil project and I can't seem to figure out why the numbers keep repeating. What is the cause of this repetition. the function that generate the numbers is below
Code:
void numGen(struct Ticket *pick){
int x;
int y;
int check = 0;
[Code].....
View 6 Replies
View Related
May 25, 2013
How to show First Non-Repeating character?
"r"
#include <iostream>
#include <string.h>
#define MAX 100
[Code]....
View 7 Replies
View Related
Jul 10, 2013
10,11,20,1512,22,24,19,22
i want to write a c++ program to build min heap which gets above values from user. remember this program should not alloduplicate values to enter. it should discard duplicate values.
View 11 Replies
View Related
May 19, 2014
I am working with cart algorithm and i have the following problem,i need to try all possible splits of n values in order to determine the best.
So lets say i have 3 values("low","medium",high) then the possible splits(pairs) would be:
(assuming low=0,medium=1,high=2)
0,1-2 low,medium-high
1,0-2 medium,low-high
2,1-0 high,medium-low
For 4 values(a,b,c,d) it would be:
ab,cd
ac,bd
ad,bc
abc,d
adb,c
adc,b
bcd,a
Problem is i dont know n so the solution must be recursive. The possible splits are 2^(n-1)-1. I am really stuck and most of the code is complete for cart and i really don't want to restrict it to binary values.
View 1 Replies
View Related
Nov 14, 2014
Question was:
QuoteWrite a program that reads in ten numbers and displays distinct numbers. If a number appears multiple times, it is displayed only once.For example: if user enters 1,1,2,3,4,4,5,1,0,9. You should output: 1,2,3,4,5,0,9. Order doesn't matter.
Steps:
a. Create an int[] to hold all the integers of user input and another int[] to store the distinct numbers.
b. Make a nested for-loops which the outer loop goes though the first array and inner loop to check if the value is already inside. Store the value to the second array if new number,otherwise do nothing.
c. Make a for loop to print out the elements of the second array
View 6 Replies
View Related
Jul 21, 2014
How do i find and output which one is most frequent from a given set of arguments on command line in c ?
View 4 Replies
View Related
Oct 21, 2014
I am having a issues with an assignment in my class and don't really understand why. I am getting undeclared identifier errors even though I have declared and I am also getting an error. Here is the code:
#include "stdafx.h"
#include <iostream>
#include <cassert>
[Code].....
Last time I came to you all with an error it was a simple brain fart on my part but I don't think this one is like that. I would love to tell you what the program is supposed to do but I still do not really know, which might be part of the problem. I guess it outputs different sized rectangles...
View 7 Replies
View Related
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
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
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
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
View Related
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
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
May 8, 2015
I am currently writing a password generator in Microsoft Visual Studios 2010 Professional. The section I am having a problem with is the practical password. It is suppose to randomly read 3 words from a text file and then display it in the text box. The program will compile and run but when I hit generate I get "True True True" and not three random words. Then this warning shows up:
Warning C4800: 'char *' : forcing value to bool 'true' or 'false' (performance warning)
//Code is from the form1.h file. I can post the rest of the code if need be but I just included my includes and the problematic section
Code:
#pragma once
#include <cstdlib>
#include <ctime>
#include <stdlib.h>
#include <cmath>
#include <iostream>
#include <iomanip>
[Code] ....
Screenshot of the warnings: [URL] .....
Picture of the output: [URL] ....
View 3 Replies
View Related
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
Nov 7, 2013
I got a permutation question, I got two different std::list:
list<string> slist;
slist.push_back("str111");
slist.push_back("str222");
slist.push_back("str333");
list<int> ilist;
ilist.push_back(100);
ilist.push_back(200);
I need the permutation for both two lists, the result should be like this:
#include <iostream>
#include <string>
#include <list>
#include <algorithm>
using namespace std;
template <typename value_t>
void dump_list(const list<value_t>& lst) {
[Code] ....
See, there are two do while loop, if I need a permutation with more than two lists, there'll be more and more do-while loops, that's make code looks ugly, I wonder if stl has some tricky way that can do this with just one next_permutation.
View 5 Replies
View Related
Dec 27, 2013
I'm trying to set up a simple implementation of a double linked list. I can't make it fly.
Code:
#include <iostream>
#include <string.h>
#include <stdlib.h>
#include <stdio.h>
using namespace std;
[Code] ...
I seem to create a root vertex, but I can't establish if I connect sub nodes to my list.
View 13 Replies
View Related
Mar 6, 2015
I am merging two linked list but the output of the program is not printing insert
Code:
typedef struct Merge
{
int info;
[Code].....
View 1 Replies
View Related
Oct 14, 2013
In our homework assignment it states to, "write a set of dynamic linked lists" and so on. Now, the problem I'm confusing myself is at the storage inside of each node. To my understanding, each node contains the prev and next nodes, but also a pointer to the data, in this case being a string. He has asked us to manage these strings as rows of chars such as
char[0] = c // first node being addressed here
char[1] = a
char[2] = t
char[3] =
char[4] = d // second node starting here
char[5] = o
char[6] = g
char[7] =
I have written my code where each node is holding a string, not separated as shown above... my question is to how you can build your doubly linked list where each node is being address a set of chars.
View 1 Replies
View Related
Apr 5, 2013
New to this C stuff, and was going through Kochan's book Programming in C and got to chapter 9 structured lists.There's this problem that requires you to set a Variable N that calculates days.
N = 1461 x f(year, month) / 4 + 153 x g(month) / 5 + day
where
f(year, month) = year-1 (if month <=2)
=year (otherwise)
g(month) = month+13 (if month <=2)
= month+1 (otherwise) Code:
struct date {
}
[code]....
I was having issues getting the right values for N so I tried to see what T1.year gives me when I type in firstDay.month=02, firstDay.day=08 and firstDay.year=1999, and I got 8. According to book I should be getting 1998.
View 2 Replies
View Related
Feb 26, 2015
I created a bunch of nodes and I made each one before one another. Im having trouble adding another node to the last one.
#include <iostream>
using namespace std;
struct nodeType{
int info;
nodeType *link;
};
void printList(nodeType *head) {
nodeType *current = head;
[code]....
The node with the value of 400 is the node that has to be last.. How would that work?
View 3 Replies
View Related
May 11, 2014
I'm trying to do is let the user type in something like A654321 (note: these are ALL the characters, i.e. 'A', '6', '5', '4', etc..) Then I just want to display that current number back to them and I am getting some weird pointer memory allocation error..
#include<iostream>
using namespace std;
//To rename data-type "int" or integer to "element" (Both are equivalent)..
typedef int element;
//To declare an appropriate SENTINEL.
char const SENTINEL = '#';
[code]....
It seems like the first part that it bugs out at is in my Clean(); function..
Unhandled exception at 0x01383FBB in VegMe.exe: 0xC0000005: Access violation reading location 0xCCCCCCD0.
It doesn't like head = head->next; ?Also, ignore the ReverseList(); function, it is not being used as of now.
View 7 Replies
View Related