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
ADVERTISEMENT
Feb 28, 2014
I'm working on a homework assignment that asks me to roll two die a user given number of times, find the roll sums, and a few other things. I'm working on it one module at a time and I'm running into two big problems so far.
The first problem is that my int variable rolls changes to a number within the random number generator range of numbers after I run rolldie. I got around this by making a const equal to the user entered value of rolls just so that I could continue developing the program.
My second problem is that the values of the arrays resultsOne[] and resultsTwo[] are changed after running findsum(). Why this is happening and I even tried passing them as const, but that changed nothing. We just started learning about passing arrays to functions, so there might be something big that I'm missing.
Code:
#include <iostream>
#include <cstdlib>
using namespace std;
void rolldie(int resultsOne[], int sizeOfresultsOne, int resultsTwo[], int sizeOfresultsTwo);
void findsum(int resultsOne[], int sizeOfresultsOne, int resultsTwo[], int sizeOfresultsTwo, int tossSums[], int sizeOftossSums);
[Code] ....
View 8 Replies
View Related
Dec 14, 2014
I'm working on a project where we access a tiny premade database in order to log into and access another page. I got the log in part working right, but the last part of the project asks me to lock out the account after a certain number of failed attempts. I'm not sure if I need a method to do this or if I can do it right there in the button handler. I tried creating a method to use on the object that was already there, but I'm not sure if that's the right way to go about it. It says it locks the account, but the value in the database never changes, and I don't know why.
//from the login button handler
protected void btnLogin_Click(object sender, EventArgs e) {
bool IsFound = false;
clsDataLayer dl = new clsDataLayer();
IsFound = dl.GetUser(Server.MapPath("~/AddressBook.mdb"), txtUserID.Text, txtPassword.Text);
if (IsFound) {
Response.Redirect("~/frmUpdateAddress.aspx");
[code]....
View 14 Replies
View Related
Jun 29, 2013
I have the following void function devised to assign "+1" or "-1" to each element of a matrix at random. While the function does what I want, when I print the values of the matrix all are set to zero:
#include <vector>
#include "aRand.h"
#include <iostream>
void initConfig(std::vector<std::vector<int> > premat, int nL, int nN) {
int * pnRand;
pnRand = 0;
[Code]...
The function pnRand_plus returns a pointer to an array of random numbers from 1 to 100, with seed time(NULL) + i. The values printed in main are zero, despite the values printed during the function run are fine (-1s and +1s).
View 2 Replies
View Related
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
Apr 7, 2013
I have an array titled: char TypeOfSong[arraySize] where the array size is 15. I am reading data from a file into this array and the characters can be either 'C', 'D', 'E', or 'R'. Each of these characters stands for a word (sting) and when I output the array, I need the strings to show up, not the characters. I have been reading online and in my book but I can only find information on turning one array with the same characters into a string. How would I go about changing this character array with different characters into a sting?
The characters stand for:
C = Country
D = Dance Party
E = Elevator
R = Rock
View 5 Replies
View Related
Jan 12, 2015
I have a 10x10 array, initialized to all zeros. I create 2 random numbers for the purpose of guessing a position in the array.
However, when I print the array, the 0,0 spot keeps shifting to match the 2nd random number generated. Is there something strange about the 0,0 spot?
Here is my code:
Code:
seedrnd();
for (x=0;x<2;x++) {
randArray[x]=rnd(10);
}
for (x=0;x<2;x=x+1)
[Code] .....
The 2nd to last print statement actually prints randColumn. The last print statement correctly prints 0.
View 7 Replies
View Related
Dec 10, 2014
I want to write a programm that will reverse the order of the numbers in an array (e.g. as an input 1,2,3.5,4 and as an output i want 4,3.5,2,1) . But i have to problems:
1) I do not know how to properly change the type of a numbers inside an array from int to float or double, changing int to float in front of the a[10], does not change anything instead the code does not want to compile then.
2) I also want to make an array of a number of elements typed by a user with use of a "do" loop and how to put this parameter in the code.
Here is my code:
Code:
// ConsoleApplication3.cpp : Defines the entry point for the console application.//
#include "stdafx.h"
int _tmain(int argc, _TCHAR* argv[]) {
int a[10], i, n;
int pom;
do {
printf("number of elements in an array a: n = ");
[Code]...
View 5 Replies
View Related
Nov 22, 2013
I'm trying building a new macro for change the array size:
#define redim(varname,x) ((sizeof(varname)*) realloc (varname, x * sizeof(varname)));
int b;
redim(b,3);
error message:
"error: expected primary-expression before ')' token"
what isn't right with these macro?
View 10 Replies
View Related
Feb 15, 2014
I am wonder what is the fastest way of changing elements in array of characters for encode purpose, here is simple example presenting an idea:
Code:
char *a = "123456789":
char b[] = "ABCDEFGHI";
int 1;
for (i=0;i<strlen(a);i++) {
b[i] = a[i];
}
Is this approach better or worse than bit manipulation ?
View 4 Replies
View Related
Feb 1, 2015
I have run across what I believe to be a syntax problem which I don't understand. I have a structure with two character array and I need to be able to change the size of those array dynamically. I have to use character arrays and I think the dot notation. I am not sure if I can use arrow notation. I can not do this problem using strings and vectors.
#include <iostream>
#include <cstring>
using namespace std;
[Code]....
View 4 Replies
View Related
Apr 27, 2013
I'm having some problems with changing an array of numbers of type char to type int. Every time i try to sum 2 array indexed values it returns some letter or symbol. Also, if i change the type of the array in the functions the compiler gives me an error message. I would also like to add that the problem requires that the first two arrays be char so each individual number gets assigned to a different value.
My current code is:
Code:
#include <iostream>
void input(char a[], char b[], int& size_a, int& size_b);
void convert(char a[], int size);
void reverse(char a[], int size);
void add(char a[], char b[], int c[], int size);
int main()
[Code]....
View 4 Replies
View Related
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
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
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
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
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
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
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
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
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
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
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
View Related
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
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
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