C++ :: Phantom Values In 2D Array

Nov 17, 2013

using Win 7 64 bit enterprise, sp1.

I'm getting unwanted values assigned to a 2D array. I'm working on a tic tac toe program as a method of building my array skills. It's just text/ascii based command prompt output, in case you are wondering.

I have a 3x3 array for the actual grid values (to determine if there is a blank, an X or an O) based on x,y position as determined by GetAsyncKeyState to use arrows for square selection.

these x,y values I use to determine the array slot, square[xX][xY]

the xX and xY values range from 0-2 respectively depending on the game square the cursor is currently in.

The problem is, some of the array values get assigned to multiple array slots, and some don't get assigned at all, although 6 of the 9 squares function correctly. It is always the same squares. (I've tried it on multiple PC's and get the same error). I reset the array to 0's when the program starts.

I have a debugging output of this array's values that show on the screen so I can keep an eye on what it is doing.

Intended operation is to select a square and assign a value of 1 indicating an X. For example, select the center square and hit the enter key it will place an X in the center square and assign a value of 1 to square[1][1].

My debugging output shows square[1][1]=1 as shown by this line of code from below

curPos(31,4); cout<<"square["<<xX<<"]["<<xY<<"]="<<square[xX][xY];

if I hit the up arrow, xY changes to 0, xX remains 1, and the cursor moves up one. If I hit enter, it will place an X in the upper center square.

Debugging output shows square[0][1]=1, but my grid tracking the values square[][] will change to square [0][0]=1, square [0][1]=1, and square[0][2]=1. function square[xX][xY]=1 get's exercised only once that I can see, yet 3 elements in the array get assigned the value of 1. square[0][0] when selected gets no value assigned.

Here is the code in question: I think the offend variables are the xX and xY, and this is the only location in the entire code where they appear, aside from declaring them.

for (a=0; a<3; a++){//reset square[][] to 0
for (b=0; b<3; b++)
square[a][b]=0;
}
drawboard();//draw large # gameboard

[Code] ...

View 7 Replies


ADVERTISEMENT

C/C++ :: Compare Values Stored In First Array To User Inputted Values In Second Array

Oct 19, 2014

Goal: Write a program that compares the values stored in the first array to the user inputted values in the second array.

In order to fix this error: [URL]...

I had to change my array initialization to one with a star in front of it:

char a1[]={"a","d","b","b","c","b","a","b","c","d","a","c","d","b","d","c","c","a","d","b"};
to:
char *a1[]={"a","d","b","b","c","b","a","b","c","d","a","c","d","b","d","c","c","a","d","b"};

I also changed my 2nd array to one with a star in front of it: char *a2[20];

What does this mean exactly? Putting a star in front of an array?

Also, I am now getting an "unhandled exception" when I try to get input for my 2nd array:

cin>>a2[i];

View 3 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++ :: Why Can't Static Array Copy Values From Dynamic Array

Mar 13, 2013

But it can the other way around

Code:
static_Array= dynamic_Array;
dynamic_Array = static_Array;

The second statement works and i'm able to print out both arrays with equal values but with the first

[code] static_Array = dynamic_Array;I get incompatible types in assignment of 'int*' to 'int [7]' is the error I get [/code]

View 2 Replies View Related

C :: Print Values Of Array From Function By Passing Array?

Nov 1, 2014

I wanted to print the values of a array from a function by passing the array as well as the number of elements to be read. For a single dimensional array, this is how i have written it. It's pretty straight forward. I want to read 5 elements from the 5th element in the array.

Code:
#include<stdio.h>
void display(int array[],int size) {
int i;

[Code]....

With this code I want to print the five elements from the element present in [0][4].

But shows an error that

Code:
D:BennetCodeblocks CLearning CSingleDimentionalArray.c||In function 'main':|
D:BennetCodeblocks CLearning CSingleDimentionalArray.c|18|warning: passing argument 1 of 'display' from incompatible pointer type [enabled by default]|
D:BennetCodeblocks CLearning CSingleDimentionalArray.c|2|note: expected 'int (*)[10]' but argument is of type 'int *'|
||=== Build finished: 0 error(s), 1 warning(s) (0 minute(s), 0 second(s)) ===|

I know when you pass a array as an argument it gets decomposed into a pointer, but with a multi-dimensional array this is not the case. how this works for mult- dimensional array's?

View 3 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 :: How To Use 2D Array In Function And Change Array Values

Apr 17, 2014

use 2D array in function and change the array values. I do not know if I can use array by calling from a function. I have 6 row 6 column array, I used it inside a function and for the another function I just need to change 4. row 4. column and I do not want to type array to just change one part. I do not know if there is another way or not

View 7 Replies View Related

C :: Store Sum Of EACH COLUMN In 2D Array Values In 1D Array?

Mar 29, 2013

How can I Figure out and store the sum of EACH COLUMN in the 2D array values in a 1D array? And to the same for the average?

View 1 Replies View Related

C/C++ :: Sum Of Even And Odd Values In Array

Feb 28, 2015

Its output is not correct

#‎include <stdio.h>
void main() {
int n,i,j,option;
int evensum=0;
int oddsum=0;

[Code] ....

View 2 Replies View Related

C++ :: Sorting Values In Array?

Feb 8, 2015

I tried sorting arr2 from lowest to highest value, but it only gives me 4 values and then the rest are zero.

Code:
#include <iostream>
#include <iomanip>
using namespace std;
int main()
{
cout << fixed << setprecision(1);

[code].....

View 1 Replies View Related

C :: Incorrect Values In Array

Apr 6, 2014

I have this simple program below:

Code:

#include <stdio.h>
#include <stdlib.h>
#include <string.h>
typedef struct {
unsigned long long int address;
float current;
unsigned char pressure_units;
} sensor;

[Code]...

As you can see, it has stored the last struct in all three indexes of the array. Why?

View 1 Replies View Related

C :: Plug In Values For Array?

Mar 26, 2014

How would i go about making a program that asks the user how many elements they want in the array and then what those numbers would be.

View 4 Replies View Related

C++ :: Changing Array Values

Jun 15, 2013

If I have an array of two columns that have the same values and I want to change only the third column how can I go about doing this. The values of the third column will change based on the values in one of the columns which I plug into a math equation. Also how come I can't show a double value in the array?

#include <iostream>
#include <math.h>
#include<iomanip>
#include <vector>
using namespace std;

[code]...

View 7 Replies View Related

C++ :: Multiply Values In Array

Jan 27, 2015

If we have array like

int numbers [] = {3,4,8,9,6,3,2,58,6,3,2,5};

how can we fast do smth like 3*4*8*9*6*3*2*58*6*3*2*5

also numbers[0]*numbers[1]*numbers[2] etc

all must be in one loop....

View 3 Replies View Related

C++ :: How To Change Values Of Array

Feb 1, 2015

how can i change the array value and display the updated value. for example this is the output beginning of the program

-----------------------------------------------------
Part Description Number of parts in the bin
----------------------------------------------------

valve 10
Bearing 5
Bushing 21
Coupling 7

[Code].....

View 1 Replies View Related

C++ :: Multiplying All Values Of Array

Nov 16, 2013

I have an array as such and need to multiply all the values of it by each other and put that as a variable.

//for example
int array1[100]
//assume i have already input the values of each element properly up to, say, element 4
//I need to now multiply all of those values together. I think I need the size of the array to control what it multiplies (I know how to find size) ....

View 4 Replies View Related

C/C++ :: Exclude Min And Max Values From Array?

Nov 28, 2014

Problem: My code works perfectly and I only need to solve one issue. When I am calculating the average, how do I exclude the min and max values from the array?

My code:

#include <iostream>
using namespace std;
int main(){
float a[9];
int x;
int sum = 0;
for (x=0; x<9; x++) {

[code]....

View 1 Replies View Related

C# :: Calculating Min And Max Values In Array?

Nov 20, 2014

my code is working as expected except a slight error, i have to find min max and median values of an inputed array terminated by 0, the problem im having is with calculating the minimum, where when i enter 0 to terminate the program it uses 0 as the minimum value. my code is as follows

public static void FindAverages()
{
try
{

[Code]....

View 3 Replies View Related

C/C++ :: Recalling Values From Array

Jul 28, 2014

I'm very new to programming and this assignment (actually my Final Project, entry level!) has already been submitted.I noticed to late that when I output my max and min values, they are not linked to string comp. The assignment is suppose to have me outputting both the Highest and Lowest company name attached to their revenue after it displays all 10 companies, etc. I completely missed that part of the assignment.

Code:
for ( int i = 0; i < 10; i++ ) {
if(rev[i]<min){
min=rev[i],comp[i];
}

Would link the 2 part of the array to max, apparently I completely screwed up there . Below is the full project.

#include <iostream>
#include <iomanip>
#include <string>
using namespace std;
int main() {
const int array = 10;
string comp[array];

[Code] .....

View 1 Replies View Related

C :: Finding Equal Values In Array

Feb 3, 2015

How i can find two equal int in array with O(n) time complexityand O(1) place complexity?

View 8 Replies View Related

C :: Pointer To Display Values Of Array

Feb 12, 2013

I am using pointer to display values of an array but its output is not correct example 23424,0, -323423 etc... whats the problem with my code:

Code:
#include<stdio.h>
#include<conio.h>
int main() {
clrscr();

int arr[10][10],rows,cols;
int* ptr;

[Code] ....

View 4 Replies View Related

C :: Split Array Into Sections Of 2 Values

Mar 16, 2013

i want to split the array into sections of 2 values, recursively. the objective its to do the average.i have this input and output, that its correct:

> media_recursiva a 1 a 2 a 4 a 5 a 2 a 3 a 5 a 6
1.000
1.500
3.000
3.500

("a 1" means add the value 1)

but mine its wrong, it gives to me this:

1.000
1.000
2.500
3.000

Code:

float media(int arr[], int count) {
while(count != 0){
if(count==1)
return arr[0];
else if(count ==2){
return ((arr[0] + arr[1])/2);

[Code]....

View 5 Replies View Related

C :: How To Properly Put Char Values Into Array

Oct 24, 2014

I'm trying to fill the array "g" with letters from the array "letras" given a certain condition. Everything is working fine, except I couldn't do it... Strange characters appear when I run the code. What am i doing wrong?

Note: This is a part of a function. "vetor" is a parameter that was passed to this function.

Code:

int i;
int j = 0;
char g[20];
char letras[5] = {'a', 'b', 'c', 'd', 'n'};
while(j < g)
{
for(i = 0; i < 80; i = i + 4)

[Code]...

View 3 Replies View Related

C :: Reading Values From CSV File Into Array

Jan 21, 2014

My problem is that I need to take a csv or excel file with tens of thousands of datapoints, write all points in a section of column to an array, perform calculations on them, and then write it back into another column.

I've been looking all over the internet for ways to do this easily. So far I have not found anything that I can follow and implement.Some codes have been slightly useful, but they aren't commented in a way I can understand. How to write code to take, for instance, lines from column b between 500-1000, write them to an array, and write another array 500 characters in column c. If that code could be commented, I have tried a few different techniques (counting commas), but haven't gotten anything to work.

View 9 Replies View Related

C :: Setting Values For Array Of Structs

Dec 18, 2013

How do I set all of these string and double value(s) to 0?

Code:

#define MAXcharacters 12
#define MAXaccounts 100
struct Records {
char userid[MAXcharacters + 1];
char password[MAXcharacters + 1];
double balance;
};

[code]...

View 3 Replies View Related

C :: Print Values Of Array By Popularity

Jan 11, 2014

Given an array with integer values in the range [0, 100], print the values by popularity (number of time it appears in the array).

example: array: 60, 60, 70, 80, 80, 80, 80, 100;

output: 80 80 80 60 60 70 100.

complexity restriction: should be linear.cant use advance data structure like lists or hashmaps, only arrays. structs are not allowed.

my idea: to build counter array of buckets of size 101, and count each value.then i need to sort the counter array(its still linear), but how i can keep track that the value of 80 appeared 3 time?I mean i need to sort the values of the counter with the indexes as well.

View 3 Replies View Related







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