C++ :: Loop Through Indexes In Guess Array And Assign M Randomly

Jan 19, 2013

Just run a loop through each of the indexes in the guessarray and assign 'M' to them randomly.

View 2 Replies


ADVERTISEMENT

C++ :: Hangman Definition Game - Extract Word Randomly Form File And User Guess The Word

Jun 25, 2014

Basically I have a text file called words. I'm supposed to extract a word randomly form the file and have the user guess the word. If they guess the word correctly in x number of tries they will receive the definition.

I'm having trouble receiving that random word and I'm getting the definitions from the file.

Here's my code:

#include <iostream>
#include <fstream>
#include <string>
#include <stdio.h>
#include <stdlib.h>
#include <time.h>
using namespace std;

[Code] ....

This is what is in the words.txt file
apple#the usually round, red or yellow, edible fruit of a small tree
boat#a vessel for transport by water
horse#a solid-hoofed plant-eating domesticated mammal with a flowing mane and tail, used for riding
television#a system for transmitting visual images and sound that are reproduced on screens
soup#a liquid dish, typically made by boiling meat, fish, or vegetables, etc.
bottle#a container, typically made of glass or plastic and with a narrow neck
barber#a person who cuts hair
toast#sliced bread browned on both sides by exposure to radiant heat
radar#a system for detecting the presence, direction, distance, and speed of aircraft, ships, and other objects
red#of a color at the end of the spectrum next to orange and opposite violet

View 3 Replies View Related

C++ :: While Loop Age Guess

Feb 20, 2013

Write a C++ program that uses a while loop to guess a persons age, ask the user if the want to try again if no end the loop. Of course if they guess it the loop also ends

View 3 Replies View Related

C++ :: Storing Integers At Odd And Even Indexes In Array

Mar 4, 2013

here is my problem given below Input values (say 10) from user in array, if the value is even then place at even index else at odd index. Then how could i solve this problem?

View 2 Replies View Related

C++ :: How To Iterate Through A For Loop Randomly

Apr 5, 2013

So I have a vector that I want to iterate through randomly, and by random I mean that each element is only accessed once but I don't want to shuffle the vector because the vector elements are large. So I want this functionality:

std::vector<SomeLargeObjectWithoutACopyConstructor> myvec;
// ...fill myvec
std::random_shuffle(myvec.begin(),myvec.end());
for (auto& value : myvec)
{
// do stuff
}

Only I don't want to do this because the object type has no copy constructor and is large, so I don't want to shuffle the vector, just the iteration path. Is there a simple and efficient way of iterating randomly through a vector while ensuring that each object is only accessed once?

View 3 Replies View Related

C++ :: Loop Randomly Until Get All Seven Numbers

Nov 13, 2013

Is it possible to loop randomly. For example

for ( int i = 0; i<= 6 ; i++ )

I don't want i to acsend from 0 to 6 but i want it to get all numbers randomly. For example

first time r = 5 second time r = 2 and so on

until it gets all the seven numbers

View 4 Replies View Related

C :: Guess 4 Int Array With How Many Are In Right And Wrong Positions

Feb 11, 2013

For an assignment I have to create a random array of four integers, and then I have to allow someone to input up to ten guesses to guess the array in the correct order. I also need to be able to display whatever was generated by inputting -1. Finally, after every guess I have to tell the inputter how many of the guessed integers are correct and in the correct position, as well as how many integers are correct but not in the correct position.

So far I've been able to get the random array to generate properly, but inputting negative one has no effect, although if I input it four times in a row I get to my 'lose' condition. Also, it only seems to allow the user to input 4 guesses and not 10 before going straight to the 'lose' condition. I need to get these issues sorted out before I can move on to showing how many guesses are right etc....

Code:
#include <stdio.h>
#include <stdlib.h>
#include <time.h>
int main()
{
srand(time (NULL));

[Code] ....

View 3 Replies View Related

C/C++ :: Assign Path For The Files In For Loop?

Jan 6, 2015

I wrote this code but it opens file in its folder Iwant to save in somewhere else. How I could assign path for the files in for loop?

for (double j = 0.5; j < 1.4; j+=0.1) {
s +=1;
stringstream a;
a << j;
filename = "Vzcr_" + a.str();
filename += ".txt";
files.open(filename.c_str(), ios::out);

View 1 Replies View Related

C++ :: For Loop In Hangman Game - Read A Word From Text File Randomly And Matches It With Definition

Jun 26, 2014

Ok here I have a program that reads a word from a text file randomly and matches it with the definition. The user has to guess what the word is according to the definition.

I'm having trouble with my for loop, I'm not getting any errors. But I just know something is off.

Here's my code:

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

using namespace std;
int main(){
int number;
int count = 0;
int numOfGuess = 0;

[Code] ...

This is words.txt:

apple#the usually round, red or yellow, edible fruit of a small tree
boat#a vessel for transport by water
horse#a solid-hoofed plant-eating domesticated mammal with a flowing mane and tail, used for riding
television#a system for transmitting visual images and sound that are reproduced on screens
soup#a liquid dish, typically made by boiling meat, fish, or vegetables, etc.
bottle#a container, typically made of glass or plastic and with a narrow neck
barber#a person who cuts hair
toast#sliced bread browned on both sides by exposure to radiant heat
radar#a system for detecting the presence, direction, distance, and speed of aircraft, ships, and other objects
red#of a color at the end of the spectrum next to orange and opposite violet

View 1 Replies View Related

C :: Max / Min Value In Randomly Produced Array

May 10, 2014

I am very much a beginner at C and a large amount of it still tends to go over my head, I've created a 2d array which its size is generated from user input and filled with random integers. Next I need to locate the maximum and minimum figures in the integer and as dull..This is the code I have so far

Code:

#include <stdio.h>#include <stdlib.h>
int main ()
{
int firstDimension, secondDimension, firstDimensionIndex, secondDimensionIndex,index;
int **table;
}

[code]....

View 2 Replies View Related

C++ :: Randomly Remove Points From Array?

Feb 19, 2013

I was wondering if there was a way to set up a code with an array of variable dimensions that removed random points on that array i.e.

1111
1111
1111

then randomly remove a point:

1101
1111
1111

and then be able to repeat this process until all points are removed.

View 2 Replies View Related

C# :: Randomly Select Strings From Array

Mar 27, 2014

I am trying to select 3 questions randomly from a string array and create another array with the randomly selected questions then display them in labels.

As you can see in the code I have used Array.Clear method to remove the selected question from the array to prevent duplicate questions being selected. For some reason this is not working! The "Randomly" selected question is ALWAYS the 5th element [4] of the randomQuestions array and this element is duplicated for each iteration of the loop.

public void shuffleQuestions() {
string questionselected;
string[] randomQuestions = {
"What is the speed limit from the time you pass an Accident sign until you have passed the crash site?",
"What must you do at a red traffic light?",
"What is the maximum possible speed limit on the open road?",

[Code ....

View 12 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++ :: Accept Integer Array And Its Size As Arguments And Assign Elements Into 2 Dimensional Array

Jan 10, 2015

Write a program using user-defined function which accepts an integer array and its size as arguments and assign the elements into a two dimensional array of integers in the following format: If the array is 1,2,3,4,5,6, the resultant 2D array is

1 2 3 4 5 6
1 2 3 4 5 0
1 2 3 4 0 0
1 2 3 0 0 0
1 2 0 0 0 0
1 0 0 0 0 0

View 1 Replies View Related

C++ :: Create Array With 800 Element That Are Randomly Arranged

Mar 31, 2013

I am trying to create an array with 800 element that are randomly arranged within the array. Once this is complete i want to use the bubble sort algorithm to organize the number in ascending order. I have the following code but it doesn't seem to work,

#include <stdio.h>
#include <stdlib.h>
#include <time.h>
#define BUBBLE 800
int main() {
int array[BUBBLE];

[Code]...

View 2 Replies View Related

C++ :: Why Assign A Pointer To Array

Jan 15, 2015

Why would you ever assign a pointer to an existing array?Take this link for example. URL....I understand that pointers use dynamic memory allocation so they are much more flexible then a built in array, but if you already have an existing array, don't you already have static memory allocation for that array? Why bother assigning a pointer? Regardless of the pointer, doesn't the program still allocate static memory to the array anyway?

View 3 Replies View Related

C :: Assign Numbers In A Buffer To 2D Array

Jul 11, 2014

How to assign numbers stored in a buffer memory to a 2D array.

The data type is unsigned 16bit (unsigned short) integers and they are stored in a 16bit/2bytes*1280*1024=2621440 bytes memory. The pointer pBuffer is the starting address of the buffer. Now I initiated an array and then assign the numbers to the array.

Code:
unsigned frame[1280][1024];
for (int i=0;i<1024;i++){
for(int j=0;j<1280;j++){
frame[i][j]=(*(unsigned short*)pBuffer+1024*i+j);
printf("%u ", frame[i][j]);
}
printf("
");
}

Because I know the number in the memory, I know after running the code that the result gives me nonsense.

I tried frame[i][j]=(*(unsigned short*)pBuffer+1024*2*i+2*j);

Since I think the pointer needs to move 2 bytes at a time, but it still gives me nonsensical array back.

Am I using the wrong expression to assign the values?

View 3 Replies View Related

C++ :: Assign Value Of Pow (2,800) To Char Array Or String

Jan 31, 2015

Assign value of pow(2,800) to char array or string ....

View 1 Replies View Related

C++ :: Assign Object Into Unordered Map Array?

Jun 17, 2013

typedef tr1::unordered_map <string, pin *> pin_cmp;
pin_cmp _pin_cmp;
_Pins[_num_pins] = new pin (pin_id, _num_pins, s, n, d);
_pin_cmp[_Pins[_num_pins]->get_name ()] = _Pins[_num_pins]; //performance profiling

What actually the code doing?

_pin_cmp[_Pins[_num_pins]->get_name ()] = _Pins[_num_pins]; //performance profiling

I am not familiar with unordered_map which still can use with array[].I am confuse unordered_map just need key and value why will have array[]?

View 1 Replies View Related

C++ :: Get Matrix Indexes From The Value

Oct 17, 2013

I have a 3x3x3 matrix with values hanging from 1 to 27.

The order is this: Code: m[0][0][0] = 1;
m[0][0][1] = 2;
m[0][0][2] = 3;
m[0][1][0] = 4;
m[0][1][1] = 5;
m[0][1][2] = 6;
.
.
.
m[1][0][0] = 10;
m[1][0][1] = 11;
m[1][0][2] = 12;
.
.
.
m[2][2][0] = 25;
m[2][2][1] = 26;
m[2][2][2] = 27;

Is there an easy way to compute the indexes given the value? For example, I know that the first index can be found by dividing the value by 9.0: Code: const int firstIndex = ceil(value / 9.0) - 1; What about the second and the third indexes? I couldn't find a pattern in the numbers, and I didn't want to iterate through the matrix (the indexes will be calculated many times).

The other option is to create arrays where the values will be indexes and the matrix indexes will be the values. I'm not sure if it is the best way though

View 6 Replies View Related

C :: How To Assign Values To Pointer Char Array

Aug 10, 2013

I can assign values to pointer character array like this...

Code:

char *array[4]={"abc","xyz","dgf","sdt"} ;

but the case is i don't know how to assign strings through key board ???? with using gets ,getchar or other suitable function

View 2 Replies View Related

C++ :: Assign String To Char Array Of Struct

May 6, 2013

#include <iostream>
using namespace std;
struct box{

[Code].....

C++Dev.cpp:23: error: incompatible types in assignment of ‘const char [15]’ to ‘char [40]’

View 2 Replies View Related

C :: Get First Integer From A File And Assign It To A Variable And Others Integers To Array

Jun 2, 2013

what I need is to get the first integer from a file and assign it to a variable and the others integers to an array. Example: Thats my file content 5 4 6 7 8 0 and that would be the code:

Code:

struct Array{
int n;
int *v;
}

[code]....

View 8 Replies View Related

C++ :: How To Assign Array To Every Element Of Another Array

Mar 29, 2014

I have been given an assignment which I understand pretty well, but I have a problem, and haven't been able to find a clear solution anywhere. I'm sort of a beginner in all this, so it's hard to understand what some people say.

So basically what I wanna do is assign a set of grades to every element in an array of a set number of students. I already have the part where you ask for the number of students you want to enter and then ask for their names and grades, but it can only enter one grade, and I can't figure out how to assign several grades and then get the average.

Here's my code, the assignment said to do it like this.

#define MAX 100
#include<iostream>
#include<stdlib.h>
#include<string.h>

[Code]....

View 1 Replies View Related

Visual C++ :: Getting Indexes Information From SQL Server?

Jan 6, 2014

Trying to get table indexes information in SQL Server 2012 I identified a strange situation for one scenarion.I have a table that contains two indexes referenced to some fields: Field_1 and Field_3 mapped over int, null columns (the number means the existing field order into the table designed few years ago...).

I am trying to get information about these indexes like this:

Code:
nRetCode = ::SQLStatistics(hstmtAux, NULL, 0, NULL, 0, (TCHAR*)(LPCTSTR)strTempTable, SQL_NTS, SQL_INDEX_ALL, SQL_ENSURE);
if (nRetCode == SQL_SUCCESS || nRetCode == SQL_SUCCESS_WITH_INFO)
{
nRetCode = ::SQLBindCol(hstmtAux, 4, SQL_C_SHORT, &swNonUnique, sizeof(SWORD), &cbNonUnique);
nRetCode = ::SQLBindCol(hstmtAux, 5, SQL_CHAR, szIdxQualif, sizeof(CHAR) * 130, &cbIdxQualif);
nRetCode = ::SQLBindCol(hstmtAux, 6, SQL_C_CHAR, szIdxName, sizeof(CHAR) * 130, &cbIdxName);
nRetCode = ::SQLBindCol(hstmtAux, 7, SQL_C_SHORT, &swType, sizeof(SWORD), &cbType);
nRetCode = ::SQLBindCol(hstmtAux, 8, SQL_C_SHORT, &swSeqInIdx, sizeof(SWORD), &cbSeqInIdx);
nRetCode = ::SQLBindCol(hstmtAux, 9, SQL_C_CHAR, szIdxColName, sizeof(CHAR) * 130, &cbIdxColName);

[code]....

Becasuse SQLExtendedFetch() is deprecated I used SQLFetchScroll() but the behavior is the same from my interest point of view.

Usally, I get the right information about indexes but in one situation I encounte a strange behavior. It's about having a clustered index into a scenario.
When Field_1 is Non-Unique, Non-Clustered and Field_3 is Clusted index I get the right information.

But if the index Field_1 is Clustered and the Field_3 is Non-Unique, Non-Clustered I get no information about Field_1 index (eg. szIdxName and szIdxColName are "" and their length is -1 that means SQL_NULL_DATA). So, I have no Index information. Within while loop, with the next iteration I get correct information about the second index Field_3.

I'm not sure whether the problem is with SQLStatistics, the bindings or SQLFetchScroll (they all always return SQL_SUCCESS). It looks like a problem with the driver when the first index is clustered.

View 6 Replies View Related

C++ :: How To Assign Char Array As User Defined String Object

Apr 17, 2014

STRING s1 = “FOOBAR”

Here STRING is a user defined class. how to assign a constant char array "FOOBAR" to string object? Copy constructor need to be same class type as parameter. and overloading assignment operator also need to be same class type. I think 'friend' can let pass another type of object rather than STRING to do operation on overloaded '=' operator. How could it be done if it is possible at all?

View 2 Replies View Related







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