C++ ::  2D Arrays - Creating Virtual Creatures By Storing A Letter Into Random Position In Array

Nov 3, 2014

So first I have to display a 2D array with all 0s, which is pretty easy.

#include <iostream>
using namespace std;
int main (){
int array[5][5];
for(int a=0; a<5; a++){
for(int b=0; b<5; b++){
array[a][b] = 0;

[Code] ....

So this displays

0 0 0 0 0
0 0 0 0 0
0 0 0 0 0
0 0 0 0 0
0 0 0 0 0

Next, this is where it gets confusing. I have to create a virtual creature by storing a letter into a random position in the array (the array can be up to 20x20 in size). Then make a function that searches the array for creatures, so it would search for that character. When it finds a creature, it should randomly decide to either move the creature to an adjacent position, or have it stay where it is. After, it should ask the user to create a new creature, or quit.

So how would I go about adding & modifying the current code to achieve what is listed above?

View 2 Replies


ADVERTISEMENT

C :: Storing Random Number Into Array

Dec 16, 2014

Code:

for(int i = 0 ; i < SIZE ; i ++)
{
scanf("%d" , & selection[i]);
srand((unsigned) time(&t));
draw[i] = rand() % 50; //feeling could be a problem with this line of code :::::

}

is it possible to do this. i am trying to get 6 different numbers stored into 6 elements of an array . this is the piece of the code i think there is a problem with. ie my program scans the numbers and then crashes at this point so think it could be something to do with the commented line?

View 2 Replies View Related

Visual C++ :: Creating A Virtual Mini Server?

Jul 28, 2014

Is it possible to create a virtual mini server (like IIS) that takes http request? I have a toolbar that queries an DLL using http request, and then that DLL stores some arguments in some XML file, which is read by an anti-malware.

Now every customer can't have an IIS server installed. Most of the end users uses Windows XP home edition. So is there a way i can create a virtual mini server that can be used in these PCs for placing http request?

View 14 Replies View Related

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++ :: Simulate Random Walk That Starts With Position 0

Mar 19, 2014

I am supposed to create a program that simulates a random walk that starts with position 0. If its odd it moves to the right (add one) if the random number is even it moves to the left (subtract 1).

#include<iostream>
#include<iomanip>
using namespace std;
void main() {
int num1, num2, num3, num4, i, rs = 12345 ;
cout << " Please enter the number iterations to be executed: ";

[Code] ....

I'm getting an error when I try to run the program: error C2106: '=' : left operand must be l-value. So I don't even know if what I have is right.

View 19 Replies View Related

C :: Capitalize Letter Without Using Arrays

Oct 28, 2014

Can I capitalize first letter of each word without using arrays ? If yes, how can I ?

View 11 Replies View Related

C :: Storing PPM Data Into Arrays

Mar 29, 2014

I am doing this program where I analyze colors in a ppm file. Now I am having a hard time storing the data into arrays in this order...

P3
600 339
255
44 5 8
44 5 8
43 4 7
42 3 6
42 3 4
44 5 6
...

So far i tried using fscanf()

Code:
#include <stdio.h>
#include <stdlib.h>
#include <math.h>
#include <stdbool.h>

#define DEBUG true
#define CHECK true

[Code] ....

I then realized that the order that the second method gave me will make it very hard for me to calculate the RGBs. Because they will be calculated like wise..

P3
600 339
255
44 5 8 = sum
44 5 8 = sum
43 4 7 = sum
42 3 6 = sum

42 3 4 = sum
44 5 6 = sum
...

but that isn't the issue right now..

View 10 Replies View Related

C++ :: Storing Values In Arrays?

Feb 25, 2014

I'm am trying to get info from a file and put it into three arrays but it isn't working.

#include <iostream>
#include <fstream>
#include <string>
using namespace std;
void sort(ifstream& infile){

[code]....

View 3 Replies View Related

C++ :: Storing Integer Arrays Safely

Apr 22, 2013

I have an assignment where I have to design, implement, and test a class for storing integer arrays "safely". I do not know how to set up the destructor.

The goal of this programming assignment is to give students practice defining and using classes. In particular, students are required to design, implement, and test a class for storing integer arrays "safely". The array should be able to hold any number of integers up to 100.

In the class header file "SafeArray.h" students must define the class and specify the constructor/destructor functions, the public methods and private variables. In the class implementation file "SafeArray.cpp" students must implement the following operations:

constructor - to initialize the object.
copy constructor - to copy an object.
destructor - to delete the object.
set - allow the user to set a value of the array at a particular location.
get - allow the user to get a value of the array at a particular location.
print - print out the array.
add - add the elements of one array to another.
subtract - subtract the elements of one array from another.

The purpose of your main program "main.cpp" is to demonstrate that all of the methods above work properly. You should have at least one call to each of the methods, and print out the array as needed to show that the operations are performing correctly.

"SafeArray.h":

#ifndef SAFEARRAY_H
#defineSAFEARRAY_H
class Safe {
private:
// Declare variables to store A, B and C

[Code] ....

View 2 Replies View Related

C/C++ :: Storing Values In Arrays Using For Loop

Nov 18, 2013

I am trying to create a program that will give me an value for a chosen from the user array ut I believe the program I've made does not recognize the values of the previous arrays. (Here is my program):

#include<stdio.h>
int main() {
int n;
int i;
int j;
float c;
float a[10000];

[Code] ....

There must be problem cause every value I give n(only for n=1 the answer is correct) the result is "a[n] is -inf"

View 1 Replies View Related

C++ :: Class Defining And Storing Integer Arrays

Apr 23, 2013

I am currently stuck on what I should do next in a program I am working on. These are my instructions:

Design, implement, and test a class for storing integer arrays "safely". The array should be able to hold any number of integers up to 100.

In the class header file "SafeArray.h" students must define the class and specify the constructor/destructor functions, the public methods and private variables. In the class implementation file "SafeArray.cpp" students must implement the following operations:

constructor - to initialize the object.
copy constructor - to copy an object.
destructor - to delete the object.
set - allow the user to set a value of the array at a particular location.
get - allow the user to get a value of the array at a particular location.
print - print out the array.
add - add the elements of one array to another.
subtract - subtract the elements of one array from another.

The output of my program is suppose to look like this:

Set q1: 2, 3, 4
Print q1: 2, 3, 4

Set q2: 1, 4, -2
Print q2: 1, 4, -2

Add q2 to q1

Print q1: 3, 7, 2
Get q1 at 1: 7

Here is the code I have so far.

*main.cpp*

#include <iostream>
#include "SafeArray.h"
using namespace std;
int main() {

// Declare a SafeArray object
Safe obj;

[Code] ....

View 1 Replies View Related

C++ :: Storing Multiple Arrays Based On User Input

Feb 7, 2014

I'm trying to create a function where it allows the user to type in multiple amounts of integers, so if the user wanted to have 3 different storages that hold different integers, the input would look something like this:

5
97 12 31 2 1 //let's say this is held in variable "a"
1 3 284 3 8 // "b"
2 3 482 3 4 // "c"
2 3 4 2 3 // "d"
99 0 2 3 42 // "e"

Since we don't know what number the user will input every time, I'm not sure how to create a dynamically allocated array that will create an x amount of arrays every time.. I want to be able to access each index of a, b, c, d, e or however many arrays there are.

So far, this is what I have, but I'm having trouble creating the arrays since it's unpredictable. I'm purposely not using vectors because I don't really get how pointers work so I'm trying to play around with it.

int* x;
int length, numbers;
cin >> length;
x = new int[length]
for (int i=0;i<length;i++)
{
cin >> numbers; //this doesn't work because it only grabs the first line for some reason
x[i] = numbers
}

View 3 Replies View Related

C++ :: Creating A Random Number Generator?

Mar 5, 2014

How would I go about creating a random number generator (or pseduorandom I suppose) with user inputted lower and upper bounds along with a user inputted size of the sequence (so they can select how many random numbers they'd like outputted)?

View 3 Replies View Related

C++ :: Creating A Random Number Generator?

Jul 13, 2014

I am creating a random number generator and have run into a problem with my do while loop. it continually prints one of the lines of output infinitely. what am i missing here?

#include <iostream>
#include <cstdlib>
#include <ctime>
using namespace std;
int main() {
unsigned seed = time(0);

[code]...

View 7 Replies View Related

Visual C++ :: Reading Character Symbols On Lines Of Text Position By Position?

Mar 4, 2013

What I have to do is write a small program in C++ to parse the symbols that are used on 5 different lines of text in each position until position 30 is reached on each line. The goal of the parsing program is to interpret the symbols (characters), if there are any per each position, on the 5 lines of text in order to output the actual data that the group of symbols represents.

My question for is this: Is there anything special from a C++ environment that should go in to something like this outside of using standard stuff like the math associated with the search algorithm that has to happen here? The symbols are located in a file, so I know I have to include "iostream" and a few other headers. But outside of header inclusions and the code necessary to iterate and streamline the search and interpretation process, am I missing anything special that I couldn't otherwise find through simple google searches?

View 6 Replies View Related

C++ :: Creating A Random Number Generator Program?

Aug 9, 2012

I'm trying to create a program that creates random numbers. I looked through some examples and this is what I came up with. The time identifier seems to be undefined yet I see no reason it is undefined.

Code:
#include "stdafx.h"
#include <iostream>
using namespace std;
int main() {
//Re-seed the random-number generator
time_t now;

[code]...

here's my error code..

1>------ Build started: Project: bake, Configuration: Debug Win32 ------
1> bake.cpp
1>c:usersjonbecherdocumentsvisual studio 2012projectsakeakeake.cpp(8): error C3861: 'time': identifier not found
1>c:usersjonbecherdocumentsvisual studio 2012projectsakeakeake.cpp(9): warning C4244: 'argument' : conversion from 'time_t' to 'unsigned int', possible loss of data
========== Build: 0 succeeded, 1 failed, 0 up-to-date, 0 skipped ==========

View 2 Replies View Related

C++ :: Creating STL Queue Of Arrays?

Dec 3, 2013

Is there any possible way to create an STL queue of arrays? I tried

queue<int[]>q;

It didn't work?

View 2 Replies View Related

C/C++ :: Error In Vector Pushback - Creating Random Unwanted Numbers

Apr 12, 2014

I'm currently writing a chunk of code that will take inputs from the user and push them into a vector until 0 is entered, at which point it will break the loop and continue on with the rest of the program. This is nothing I haven't done before, but I have never encountered this error.

The code chunk looks like this:

typedef vector <int> ivec;
int main() {
ivec nums;
int input;
while (true) {
cout << "Enter a positive integer, or 0 to quit" << endl;

[Code] ....

My standard testing input has been 3 5 6 3 8 (then 0 to quit), so one would expect my sequence to be 3 5 6 3 8...but instead after the 8 I get a random number value that is usually quite large and I cannot figure out where it comes from (ex. 3 5 6 3 8 201338847).

View 9 Replies View Related

C :: Creating Variable Length Arrays

Oct 24, 2014

How do you prompt the user to enter the number of elements for the array and use that information to creatr a variable length array? And then how do you prompt the user to enter in a number for each element of the array and scan in the appropriate numbers? the numbers are double precision floating point.

for example,
Enter the numbe of elements in the array: 3
Enter element 0: 3
Enter element 1: -1
Enter element 2: 4

I know it starts with

int main() {
double N;
int a[size];

printf("Enter the number of elements in the array:" );
scanf("%f", &size);

//I'm pretty sure this is wrong

View 8 Replies View Related

C/C++ :: Creating And Accessing Info From Arrays

Mar 1, 2014

I'm working on a project where I have the user enter storm data about hurricanes for multiple seasons. I need to make separate arrays for:

1. the month, wind speed, and min. press.
2. the category of the storm

What I'm having trouble understanding is how to make the software take an input, assuming from a scanf, and put it in an array. Then taking that value and output-ing it back out when needed.

So here is piece of my code. Note: Disregard the commented sections of the code, my current project is building off a previous one, where in the last project we were using loops, now we are using arrays.

case 1:
{
if (year > 0) //begins counting
{
/*num_trop_storms = 0*/ num_hurricanes = 0, year = 0, wind_speed = 0,
hcat1 = 0, hcat2 = 0, hcat3 = 0, hcat4 = 0, hcat5 = 0, hrun = 1, totalhurr = 0;
knots = 0, cummwindspeed = 0.0;

[Code] ....

In the code above, how exactly the scanf takes the inputs from the user and then stores them for me to access. So, I want my array to be 3 columns, for months , wind_speed, & minpress. The array has a undetermined amount of rows. I think if I figure out the first array, I can handle the second.

View 7 Replies View Related

C++ :: Creating Dynamic Arrays / Structures

Feb 7, 2012

We are supposed to create a menu with an option to add a car (make, model etc) to inventory. I have the structure format set up as far as adding the car, but I am stuck on how to make it a dynamic array of structures or whatnot (I'm not really sure on what I'm trying to do in the first place!) Basically, the user can choose to add a car and its info in. How do you set up the array to add whatever number of cars is needed? Will it be able to add more cars should the user come back to the program later?

This is the instruction of this portion of the project :

Menu Application
Add a car to inventory
Prompted to add
Make, Model and Year, Color, Miles, Price
Finish (adds the car to the file)
Cancel takes you to the main menu

View 1 Replies View Related

C++ :: Arrays Getting Random Numbers

Oct 30, 2013

Ok so Im suppose to make this program were the user inputs the size of the array then the user sets a certain range min and max for random numbers to be generated. I have a function named fillarray()

#include <iostream>
#include <cstdlib>
#include <ctime>
using namespace std;
int fillarray();

[Code] ....

Whenever i run the program i keep on getting a loop for the size of the array.

View 1 Replies View Related

C++ :: Creating Table Of Arrays - Find Maximum Value And Sum

Aug 12, 2014

I have an array of "2,3,4,5,6,9,10,11,12,99". I need to create a table of this which i have done using case

1. Find the maximum value of the array
2. Find the sum of the first and last element of the array
3. Swap the adjacent pairs of arrays
4. Display the values in array
5. Quit

Please enter choice:

but when i try running the program i did i keep having the break or continue pop up ....

#include <iostream>
using namespace std;
int main() {
int choice;
int number[10] = {2,3,4,5,6,9,10,11,12,99};

[Code] .....

View 6 Replies View Related

C++ :: Creating Crystal Lattice - 3 Dimensional Arrays

Apr 14, 2013

I receive unexpected outcome in my program. Instead of getting all combinations of 0, 1, 2 (i.e. 000, 001, ..., 222) I get only 000 001 002 010 011 012. The idea of the progarm is to create a crystal lattice. Each atom of the lattice has 3 coordinates (x, y, z). That's why I create class Atom. Then I create 3-dim array of the type derived from class Atom. Now each element of the class will represent an atom.

Code:
#include <iostream>
using namespace std;
class Atom {
public:
float x, y, z;

[Code] .....

View 2 Replies View Related

C/C++ :: Take Values From One Array And Searches For Their Index Position In Another Array

Dec 9, 2014

My program takes the values from one array and searches for their index position in another array (linear search algorithm). This is an example of the issue im having(its not part of the actual code below)

a[]={1,2,3,4,5,6}
Arr[]={1,2,2,3,4,5}

If it finds 1 in arr, it returns 0, which is fine but if it finds 2 in arr it return 1 and 1 instead of 1 and 2.

for (int q=0; q=size2;q++) {
int rs=secfunc(array1;size1;array2[q])
if(rs>=0) {
cout<<rs << "";

[Code] .....

View 4 Replies View Related

C++ :: Random Numbers Between 1 To 5 For Variable Of 5 Arrays

Sep 14, 2012

I want to have the random numbers between 1 to 5 for a variable of 5arrays. for having the random numbers i am using the code as below.

Code:
for(int i=1;i<=5;i++)
{ int j=rand()%5;
cout<<j<<endl;
}

The problem with this way of generating random number is that i get the same set of random numbers in every outputs. Is there any other way to have different random numbers with many different outcomes as much as possible.

View 7 Replies View Related







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