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


ADVERTISEMENT

C++ :: Simulate Random Walk In 2 Dimensions

Jan 6, 2015

I am writing a piece of code that simulates a random walk in 2 dimensions (an object chooses whether to move up, down, left or right randomly). I would like the program to run the simulation for many objects at the same time. The way i have written it means that for every object i add the code becomes about 40 lines longer. Any method that would simplify the code so that i could have many objects but not pages and pages of code.

#include <ctime>
#include <cstdlib>
#include<iostream>
#include<cmath>
#include<iomanip>
#include<fstream>

using namespace std;
double dist(int a, int b);

[Code] .....

View 5 Replies View Related

C++ ::  random Number Generator To Simulate A Critical Hit

Oct 25, 2013

I am trying to make a random number generator to simulate a critical hit if the number generated is from 0-critical amount. However, every time i run the code, despite being within the parameters set by the if statements, it always runs through as a critical hit and never a regular hit.

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

[Code]...

There are four attempts to save time in getting a good result.

View 6 Replies View Related

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 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++ :: Fractal Starts Zooming Out

Apr 11, 2013

I'm trying to zoom into a fractal and to do this I'm using mouse click to calculate where the centre should be and then taking away 1 from the right and top and adding 1 to the left and bottom to make a zoomed in version. This works perfectly... for 15 zooms. When the value of the left and right meet each other the fractal starts zooming out instead of in. Through multiplication maybe?

View 3 Replies View Related

C++ :: How To Start Counting Time When Program Starts

Apr 7, 2013

I want to know if there is a function or library that starts counting time when the program starts. Because I'm making a program that is dependent on time.

Pseudo code

time starts
if ( seconds % 2 == 0 ) {
counter++;
}

View 2 Replies View Related

C/C++ :: Merging 2 Files Program Starts But Does Not Complete

Oct 9, 2014

I'm having an issue with merging two files. Basically, my instructor gave me pseudocode and two files to merge together. Each file (a male client and a female client file) has three names and id numbers inside. The finished MergedClients.rtf should have all six clients in ascending ID order. I wrote the C++ code and after combing through a couple times to fix a few errors, it finally ran. The problem is it starts the process, but it doesn't ever finish.

I tried changing some of the bool expressions thinking I mixed up the true and false parts. After that the program ran and it created the new output file, but the file was empty. So, I don't think I mixed any of those expressions after all.

#include <iostream>
#include <fstream>
#include <string>
using namespace std;
int main(){
ifstream inFile1;
ifstream inFile2;

[code]....

View 10 Replies View Related

C :: Delete A File When Function Is Called And Starts Its Loop

Apr 24, 2013

I have a function and i want to delete a file when the function is called and starts it's loop i have used this code but unfortunately the file is not deleted ?

Code:
void evaluate(void) /*evaluate the population */{
int mem;
int i;
double x[NVARS+1];
char buffer[101] = {"save.txt"};

[Code] .....

View 7 Replies View Related

C++ :: Generate Calendar For A Year - Day Of Week Month Starts From

Oct 18, 2013

So for my C++ class I am required to create a program that will "Write a program to generate a calendar for a year. The program should accept the year and the day of the week for january 1 of that year (0=Sunday, 1=Monday, etc.)" (problem statement) and I am completely stuck. I've posted what I have so far below:

#include <iostream>
#include <iomanip>
using namespace std;

bool isLeapYear(int year);
int daysInMonth(int month, bool lpYear);
int printCalendar(int month);
int printDay(int dow);

[Code] .....

View 3 Replies View Related

C++ :: Creating Frog Leap Game That Starts At 1 And Finishes At 12

Feb 13, 2015

I have been given the task of creating a frog leap game that starts at 1 and finishes at 12. The layout is as follows. The '@' symbols are just included to show blank white space.

1-----2 @@ 3---4
|@@ |@@@ |
|@@ |@@@ |
5@@ 6------7-----8
|@@ @@@ |@@ |
|@@ @@@ |@@ |
9----10 @ 11 @12

Each number within the game will represent an object, the user will have to reach the 12th leaf start from leaf 1. the frog can only move in the directions of forwards backwards, left and right. Any starting points? E.g. using and array or list? i have a feeling this is going to be a big task. is inheritance possible?

View 1 Replies View Related

Visual C++ :: Loading A File And Indexing Line Starts

Jun 14, 2013

I've spent some time trying to performance test various methods of loading / accessing a file, either into memory or through a memory mapped file, but I am having some trouble.

FILE * pFile;
std::ifstream ifs;
MapViewOfFile

I'm have trouble because Windows appears to cache the file, so I am getting very mixed results. Sometimes a huge file (100's MB's) will load quickly, other times almost instantly.

How to stop Windows from doing whatever it's doing, so I can see the real time taken to load/access a file from disk?

View 8 Replies View Related

C Sharp :: How To Pick Date / Time When Serial Port Starts Reading And Also When Stops

Aug 18, 2014

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.IO;
using System.IO.Ports;

[Code] ....

How to pick date / time when serial port starts reading , and also when reading stops ?

View 2 Replies View Related

C :: UDP Application Simulate Packet Loss

Aug 12, 2014

have udp server-client application written in C. On the client side packet loss is detected using recvfrom function and sequence numbers of packets. How can I now simulate dropped packet's on the client side, for example if server is sending 1000 packet I want to drop 20% of them? I want to do this in the code, not for example using ip tables or WANEM or something like that. And one more thing, I have few clients and I want that they can dropped different packets, not the same one.

Code:
while(1){
nbytes = recvfrom(socket, buffer, MAX_SIZE, 0, (struct sockaddr *) &srv_addr, &addrlen);
if (nbytes != -1) {
// packet is received

}else{
//packet is not received
}
}

View 2 Replies View Related

C++ :: Program To Simulate Coin Toss

Nov 14, 2013

Write a program that simulates coin tossing. For each toss of the coin, the program should print Heads or Tails. Let the program toss the coin 100 times and count the number of times each side of the coin appears. Print the results. The program should call a separate function flip that takes no arguments and returns 0 for tails and 1 for heads. [Note: If the program realistically simulates the coin tossing, then each side of the coin should appear approximately half the time.]

View 7 Replies View Related

C++ :: How To Simulate File Space Allocation

Mar 29, 2014

I want to write a c++ code that due the structure of file space allocation,Simulates file system with 2*n array. Each column represents a sector. The first row is for storing files And second row holds the address of the next sector (Number of columns). And With each click on keyboard Create a file with random size and automatically find Appropriate sectors by using disk allocation method (or index allocation)... Also File names should be asked from user... And we should have file table Where the starting address of each sector,file extension and file size is given..

View 1 Replies View Related

C++ :: Implementing Class To Simulate A Disk

Oct 1, 2013

So this code compiles without any problem but it is not producing the correct output. I know there's a problem in either my getBlock or putBlock functions but I can't see it.

Currently the output is "Should be 32 1s: "
"Should be 32 2s: "

There should be 32 1s and 32 2s and nothing is coming out.

#include <iostream>
#include <fstream>
using namespace std;
class Sdisk {
public :
Sdisk(string diskname);

[Code] .....

View 3 Replies View Related

C++ :: Get Live Data To Simulate Algorithm?

Apr 9, 2014

How to get live streaming of stock data from yahoo finance? Using C++. I need the code and fetch the data so I can do calculations on the price and volume or what not.

View 1 Replies View Related

C/C++ :: Can Use Packed Structure To Simulate Memory?

Oct 11, 2013

I am trying to simulate memory in C. I want to create a structure in C that will hold a 8bit opcode and a 32bit memory address. This would simulate a 40 bit instruction for my simulator.

I read in an old book that packed structs could be used for this to not waste space. What are the draw backs for using this? I am not worried about wasting space, but just looking for a simple way to access the memory instructions. Below is a sample of the structure that I want to use.

struct memory_area {
unsigned int opcode:8;
unsigned int address:32;
};

View 2 Replies View Related

C :: Simulate Process Of Placing CDs In CD Container Using QUEUE

Sep 16, 2014

I'm in need of the C program which will simulate the process of placing and removing CD's in CD container using QUEUE.

View 4 Replies View Related

C :: Simulate Roll Of A Dice - How To Use Rand Function

Sep 23, 2014

I saw a program in which it uses rand like this:-

d1=rand() % 6+ 1;

where, d1 is any integer. The program is to simulate the roll of a dice. The whole program is this:-

Code:

#include<stdio.h>
#include<stdlib.h>
main() {
int i;
int d1, d2;
int a[13];

[Code] .....

View 10 Replies View Related

C++ :: Simulate Adding Machine - Total / Subtotal

Mar 28, 2013

Write a program that simulates an adding machine. When a zero is entered it should print the subtotal of all the numbers entered from the last zero that was entered and reset the subtotal. When two consecutive zeroes are entered it should print the total (not the subtotal) of all the numbers entered and terminate the program. Example:

1
2
3
0
subtotal 6
4
5
-2
0
subtotal 7
8
0
subtotal 8
0
total 21

Be careful this program needs a bit more thought than you might think at first. To get full credit you must make sure it also works for the 0 - 0 case. Example:

0
subtotal 0
0
total 0

The problem is, after I enter the integers and type 0, it shows the subtotal which is what I want; however, when I type more integers and type another 0 to see the subtotal again, it shows the total instead. The subtotal should reset whenever a single 0 is typed and the total should only show when two 0's are inputted simultaneously. Also, after the user enters two 0's simultaneously and views their total, I want the program to exit by saying "press any key to exit." Is there a special name for that to happen? Here is my code:

#include "stdafx.h"
#include <iostream>
using namespace std;
int main() {
int subtotal = 0, total = 0, number = 0;
bool input_zero = false;

[Code] ....

View 2 Replies View Related

C/C++ :: Linked List To Simulate Text Editor

Mar 10, 2015

I am trying to make a text editor in C++ that uses Linked Lists as the main driving force. I need to make a program that can add a line of text at a certain point, delete a certain line of text, print the entire text, and quit and save the text to the original text file inputted from the shell script. My problems are with the cpp file, and the linked list files. My remove function is not what I need it to be I know that. I also know that there are some problems with my cpp file myEditor. My code is below.

#include <sstream>
#include "linkylist.h"
#include <iostream>
#include <fstream>
#include <string>
#include <cstdlib>
using namespace std;
int main(int argc, char *argv[]) {
//node* head = new node;

[Code] ....

View 6 Replies View Related

C Sharp :: Simulate (automatic) Mouse Right Click

Aug 22, 2013

How to simulate(automatic) mouse right click operation using c#?

View 2 Replies View Related

C++ :: Program To Simulate Customers Lining Up To Buy Tickets For Some Event

Oct 17, 2013

Create a line class using a linked list that acts as a queue (first in, first out) both enqueue and dequeue. Complete the line class so that customers can be added or removed from the line. Implement the line as a linked list of customer objects that you have developed yourself or use the vector class.

View 2 Replies View Related

C++ :: Pointer Arrays - Program To Simulate Squares Most Landed On

Jun 8, 2014

I have not been using pointers that long i most of my stuff has not needed them but now they do i need to learn how to use them more. I'm writing a program that simulates the squares most landed on(for fun) and i cant get a method to work because of an array pointer.

The error is no matching function for call to 'GameLoop::Loop(int, int (*)[4])'

Here is the latest version of the code. I've been editing a lot of things so there might be some stupid errors but I've tring everything.

rolling.h and rolling.cpp are just some dice function they are working perfect.

main.cpp

#include <iostream>
#include "Rolling.h"
#include "GameLoop.h"
Rolling Roll;
GameLoop Game;

[Code] ....

View 2 Replies View Related







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