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
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
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:
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]); } }
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?
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 << "";
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
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;
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) ....
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++) {
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
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];
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)
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.
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.