C++ :: Values Are Changing When Passing Arrays And Array Sizes?

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


ADVERTISEMENT

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++ :: Adding Two Arrays With Different Sizes

Sep 6, 2013

#include <iostream>
#include <array>
#include <sstream>

[Code].....

I need to add thevArr[I] and vArr1[I] and store in vArr2[I] but I cant figure out how to drop the value or replace with a 0 if vArr is bigger than vArr1. IE: 1st number: 123 2nd number: 4567

Ill get something like this:
1 2 3
4 5 6 7
5 7 9 -827349

View 2 Replies View Related

C :: How To Declare A Group Of Arrays Of Different Sizes

Oct 15, 2013

I'm building a box to take in several arrays of different lengths. one group happens every 10 seconds. one of them happens every 5 seconds. this is from a weather station.

10 sec
subgroupA[14]
subgroupB[24]
subgroupC[17]
subgroupD[12]
subgroupE[34]

5 sec
subgroupC[17]

I plan to retransmit them, substantially unchanged at a lesser rate to save radio power over a serial data link. buried in groupD, I want to change a few chars before retransmit.

I don't want to go to the trouble of doing a structure for each of them since most will be resent unchanged. some entries are chars, some are decimal, some are a mix. I guess it might be convenient to further define groupD, maybe not.

what is the best way to declare the group? I want them to be contiguous since that's how they will end up in the tx buffer. Each subgroup has its own checksum, so I planned it this way to make checksum more convenient.

View 6 Replies View Related

C/C++ :: Two Arrays With Different Sizes Into One 2 Dimensional Vector

Mar 24, 2012

I am using 2 ARRAYS OF DIFFERENT SIZES in One 2-Dimensional Vector, and my output is not correct. The arrays are size 4 and size 13.

I want COLUMN 0 to have: 55, 66, 77, 88.

I want COLUMNs 1-12 to have 1,2,3,4,5,6,7,8,9,10,10,10,11 in EACH ROW. It would seem that the 2nd loop for the size 13 array would need to loop 4 times in order to fill 4 rows, however, I'm not sure how to do that. Here is what I have so far in code and output:

#include <iostream>    
#include <vector>  
using namespace std;  
int main() {
    int typeArray[4] = {55,66,77,88};
    int valArray[13] = {1,2,3,4,5,6,7,8,9,10,10,10,11};  

[Code] ....

OUTPUT:
55 0 0 0 0 0 0 0 0 0 0 0 0
1 2 3 4 5 6 7 8 9 10 10 10 11
77 0 0 0 0 0 0 0 0 0 0 0 0
88 0 0 0 0 0 0 0 0 0 0 0 0

How to populate rows correctly?

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++ :: Passing Stuct Array To Function But Gives 0 Values

May 9, 2014

This read a file (arrival time , brust time) for n processes and suppose to do shortest job first scheduling. the file read correctly but passing the value to SJF function gives read of 0's to all values .

#include<stdio.h>
#include<stdlib.h>
typedef struct {
int brust_time[10];
int arrival_time[10];
}Time;

[Code] .....

View 1 Replies View Related

C++ :: Passing Values From Text File To Integer Array

May 24, 2013

I'm trying to passing values from a text file to an array. The values in txt file is;

0 2 3 5
1 2 5
0 1 3 6
1 3 5

I need to store these values in an array like that

Code:
int array[?][?]={{0,2,3,5},{1,2,5},{0,1,3,6},{1,3,5}};

View 1 Replies View Related

C++ :: Passing Values Into Array Using For Loop From Input File

Jul 5, 2014

I'm trying to pass these numbers into the array using the for loop: 1, 2, 3, 4, 5. I created two files in my project called "inStuff.txt" and "OUTPUTS.txt". I know I have an error at my input in the for loop, which is a bit similar to my problem or something? I'm also on linux using a crossGCC complier(not sure if that makes a difference).

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

[Code]....

View 4 Replies View Related

C/C++ :: Transfer Array Values To Positive And Negative Arrays?

Oct 21, 2014

I have a problem with my assignment. I would like to ask how to transfer positive and negative values from array temperature to arrays positive and negative?

#include <iostream>
#include <iomanip>
using namespace std;
int main(){
int n=0, d=0, temperature[20], sum;
int positive[], negative[];
float avg;

[code]....

View 5 Replies View Related

C# :: Changing Database Values?

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

C++ :: Changing Values In A Matrix Using Void Function

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

C :: Assigning Values To Arrays / Printing Arrays

Jul 1, 2014

Using a for loop, construct two 100 element arrays, x and y, such that element i of x stores the value sin(2*pi*i/100)) and the corresponding element of y stores cos((2*pi*i/100)). Print the values stored in the elements of x and y as you calculate them.

I have attempted to solve it but I'm not sure why the value 0 is only being printed, maybe I haven't assigned sin(2i/100)) and cos((2i/100)) to the arrays properly?

Code:
#include<stdio.h>
#include<stdlib.h>
#include<math.h>
int main () {

[Code] .....

View 3 Replies View Related

C :: Passing Arrays Into Functions

Nov 4, 2013

i have a program that works, but now I am trying to get function1() to work. What it has to do is bring in the array and populate it with random letters. I don't know much about functions.

Code:

#include<stdio.h>
#include<stdlib.h>
#include<time.h>
#define maxrow 20 //defines maxrow as a constant of 20
#define maxcol 30 //defines maxcol as a constant of 30
}

[code]....

View 2 Replies View Related

C :: Passing Arrays To Other Data Has Pointers?

May 7, 2013

I am looking for an example of when passing arrays to other data that has pointers,

I understand the terms I would just like to see a small example of code that actually demonstrates this process.

View 4 Replies View Related

C++ :: Passing Positive Numbers In Arrays

Nov 1, 2013

I am having an error at line 21. Specifically the code where it says "list[num]=x"

How am I able to fix this code to do what I want? The purpose of my program is to enter in positive numbers in an array (and having it end when 0 is typed) My program also accepts negative values but will ignore them when it is outputted. I believe I have all the code right except for line 21.

#include<iostream>
using namespace std;
const int ARRAY_SIZE(25);
void read_list(const int list[],const int ARRAY_SIZE);
int main() {
int list[ARRAY_SIZE];
read_list(list, ARRAY_SIZE);

[Code] ....

View 2 Replies View Related

C++ :: Passing Structure Arrays To Functions?

Oct 31, 2013

Description: Use functions and structures to simulate storage in a warehouse

*/
#include <cstdlib>
#include<iostream>
#include<cmath>
#include<iomanip>
#include<string>
using namespace std;
struct Bin {std::string name; int Quantity;}; //create a structure for "Bin"

[code].....

I keep getting a linker error on every function. what am I doing wrong?

View 2 Replies View Related

C++ :: Passing Char Arrays Between Functions Of Same Class

Nov 16, 2013

I'm having trouble with passing a character array between functions of the same class. I have a function, buildGraph, that calls function getNextLine. The getNextLine essentially just retrieves the next line of an input file and stores it into a "char line[80]". However when I try to use "line" in my buildGraph function, it has nothing in it.

Here's my code:

Class
#define NUMNODES 10
using namespace std;
#pragma once
class Prog3Graph

[Code] ....

View 4 Replies View Related

C++ :: Passing Dynamic Multi-Dimensional Arrays

Jan 29, 2015

I need to create subfunctions to do basic Matrix mathematics (addition, subtraction, etc.) I need to be able to pass bot of my Matrices to subfunctions. I started with the addition sub function and I cant get the code to run. I keep getting expected primary-expression before ']' token error for line 75.

#include <iostream>
#include <stdio.h>
using namespace std;

[Code].....

View 1 Replies View Related

C++ :: Passing Struct Arrays To A Function By Value Not By Reference?

Mar 16, 2013

I am working on incorporating a function in to an already existing piece of code, I have incorporated the function fine as far as I am aware.

The problem I have is that I am trying to pass two int arrays to the function, so that i can manipulate and compare them "the values will be changed the originals cannot be changed"

I am having trouble pulling the information out of the already created array, I am able to pass the pointer reference for the single value which is not exactly what i want "best_prog".

My function is below I have commented the memcpy parts and also the majority of the code isn't there cause it is not needed to see make the copy work.

int edit_distance(int index) {
struct prog *progp = &population[best_prog];
/* The struct of best prog not sure if i need one for the other prog I am trying to compare it with the one below doesn't work as intended.*/
//struct prog *progp = &population[];
int editdistance = 0, ar1 = 0, ar2 = 0, a = 0, b = 0, j = 0, x = 0;

[code].....

View 12 Replies View Related

C/C++ :: Functions Passing Size Of Arrays As Value Parameters?

Mar 11, 2014

we were given this code:

// Music Shuffle Program
// This program takes an array of strings and randomly permutes their order.
// This allows us to generate new song shuffles.
#include <iostream>

[Code]....

or are they referring to something else?

View 4 Replies View Related

C :: Passing Values To Other Function?

Jul 6, 2013

The program asks for to ask the user for how many students there are, and how many strawberries they picked. The farm gets to keep half and the students get to keep the rest.

I am using functions and passing values to one function to another. I know I am making it harder then I need to, but I want to work with functions more and passing values. I figured it was better to practice with simple programs.

Code: #include <stdio.h>
float people(float);
float strawberries(float x);

[Code].....

View 4 Replies View Related

C++ :: Passing Values To Functions?

Jul 29, 2013

I am trying to get some confirmation about how to pass to functions. If you want to assign default values to certain parameters, and have others defined inside the body of int main(), then the parameters which will have default values go at the end of the list. Is that correct?

i.e. The following code is wrong, because we cannot leave a black in the function call on the third line of the main function. However, if we switch the prototype to void Passing (int a, int c, int b = 1); and the function definition to void Passing (int a , int c, int b) everything will be okay and we can call the function as Passing (a, c).

In brief, we cannot do this EVER:
Passing( a, , c)right?
#include <iostream>
using namespace std;

[Code]......

View 4 Replies View Related

C# :: Passing Values From Different Forms

Mar 21, 2014

So form two needs to pass information that was typed in its text box to form 3. So then form 3 can use this information. I think I am creating a new instance of form 2 because I get the exception can not divide by 0 so it is empty even if I typed in a integer in the text boxes. How to pass information from the textbox to a var that can be used in another form.

public partial class MapProperties : Form {
private int _numRows;
public int NumRows {
get { return _numRows; }

[Code] ....

View 2 Replies View Related

C++ :: Passing / Returning Character And Integer Arrays With Functions

Jun 21, 2013

Passing and returning character and integer arrays with functions using simple programs...use pointers if necessary

View 1 Replies View Related

C :: Passing Values To A Function Error

Apr 29, 2014

I'm working through the Let us C book. One exercise asks me to collect int and float , then pass them to a function that gets product of these and returns it to main. My code looks like this:

Code:

#include <stdio.h>#include <stdlib.h>
main()
{
int a;
float b, c;

[Code]...

So while compiling i get an error about conflicting types for product. I tried to google that error but couldn't understand what's the problem. My only clue is that i can't pass int and float to a function at the same time... Could that be it?

View 6 Replies View Related







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