C++ :: Finding Sum Of Third Row In 2D Arrays

Apr 29, 2014

Okay, so I am developing a program that does many things. One of the is finding the sum of the third row in an array.

Here is my program

#include <iostream>
#include <string>
using namespace std;
void changeNum (int qArray2D [5][5]);
void printNum (int qArray2D [5][5]);
void calcNum (int qArray2D [5][5], int sum);

[Code].....

View 14 Replies


ADVERTISEMENT

C :: Finding Minimum In Two Dimensional Arrays

Mar 30, 2014

I am having a little trouble finding the minimum value in my two dimensional array. I feel like my code is right, but it could be returning the wrong value. Below is my code, this is just my "minimum" function!

Code:
int minimum( int array[][MAX], int size ) {
int i,j,min;
for( i = 0; i < size; i++ ) {
for( j = 0; j < size; i++ ) {
if( array[i][j] < min ) {
min = array[i][j];

[Code] .....

View 4 Replies View Related

C++ :: Using Arrays As Sources Of Data For Arrays In A Structure?

Feb 6, 2014

I define "Comwords" as a string, but apparently it takes the members as chars, then I can't set strings in a structure equal to the chars.

I see to also be having unknown problems with the ComMAL array and loading it values into another element of the same structure.

How to correct this? I was thinking of casting char elements as strings, but could find no reference in my library book regarding how to do that (lots on casting int's a doubles...)

Code:

int _tmain(int argc, _TCHAR* argv[]) {
int comm = 10;
int targ = 5;
int death;
struct AI_WORDS

[Code]....

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++ :: Ranged For Loop With Arrays Of Arrays

Dec 17, 2014

int arr[4][5];
for (int(&row)[5] : arr){
for (int &column : row){
} }

Why do we name it row instead column?

int arr[row][column]

Wouldn't this be like

int arr[4][5];
for (int(&column)[5] : arr){
for (int &row: column){
}

It just seems funny to me because we use row[5] which should be 4 if we meant row? Or did I read it wrong in C++ prime !?

View 2 Replies View Related

C++ :: Dynamic Creation Of Arrays Of Pointers To Arrays Of Pointers

Apr 15, 2013

I'm trying to write a function that takes a 32bit address and a data to store at this address.

I'm wanting to take the 32 bit memory address eg 0x12345678 and split it
into 4 x 2 bytes
12, 34, 56, 78

then each of the 4 entries is at most a 256 entry array.eg
FF, FF, FF, FF

So in this example, 0x12 points to 0x34 in the second array, which points to 0x56 in the third array, which finally points to 0x78 in the last array. This last array holds the actual data.

After successfully doing 0x12345678, say I might get a read for 0x1234AABB. So, the first and second pointers already exist, but I then have to create and write to dynamically created arrays.

The arrays need to have all entries set to NULL so that i know whether to follow the pointers to overwrite a previously entered value or create new arrays and pointers.

It all looks good and simple in the pseudo code I've written up but I'm having trouble coding it. I'm currently trying to deal with the first entry case, ie all array elements are NULL, but I'm getting confused with the pointers and creation of new arrays.

void cpu::store(unsigned int mem_add,unsigned int mem_val) {
int first = (mem_address&4278190080)>>24;
int second = (mem_address&16711680)>>16;
int third = (mem_address&65280)>>8;
int fourth= (mem_address&255);

[Code] .....

A1 has been declared as
int* A1[256] ;

View 3 Replies View Related

C :: Finding Next Day Using Structures

Jul 21, 2013

Ok, for my Sunday homework I have to find the next day of the year using structures. Now, I can get the structure to read the entered date (tested that with a simple scanf to printf entered data), but I need to get it to be able to tell that it is the end of the month and print out the next month when necessary. Here is what I got so far:

Code:
//Cameron Taylor
#include <stdio.h>
struct Date{
int month;
int day;
int year;

[Code] ....

As you can see, I am trying to use an array for the max day of each month (excluding Leap Year for now).

Where I use the entered month to = 'i'. Then I use 'i' as the position in the array to see if next.day is = to the max day of that position of the array.

I am having no compiler issues with GCC using -w or -Wall, but after entering the current day the program stops working and doesn't go beyond the input.

commiedic@localhost Project18$ gcc -o -Wall Exercise4.c
commiedic@localhost Project18$ gcc -o -w Exercise4.c
commiedic@localhost Project18$ gcc -w Exercise4.c
commiedic@localhost Project18$ make Exercise4
make: `Exercise4' is up to date.

[Code] .....

View 13 Replies View Related

C++ :: Finding A Value In 2D Array?

Jul 9, 2014

I want to search a 2D array to see if it contains a certain value x. I can come up with three different ways to do this. Provided I have:

const int Rows = 40;
const int Columns = 30;
int SampleData[Rows][Columns] = { ... }

Is there any real difference (in terms of performance etc.) between these, or are there an even better solution?

Solution 1:
for(unsigned row = 0; row < Rows; ++row) {
for(unsigned col = 0; col < Columns; ++col) {
if(SampleData[row][col] == x) {
// found
} } }

Solution 2:
int* data = &SampleData[0][0];
if(find(data, data + Rows * Columns, x) != data + Rows * Columns) {
// found
}

Solution 3:
int* data = &SampleData[0][0];
for(unsigned i = 0; i < Rows * Columns; ++i) {
if(*data++ == x) {
// found
} }

View 1 Replies View Related

C++ :: Finding Max Number

Nov 5, 2013

#include <iostream>
using namespace std;
int max(int num1, int num2, int num3);
int main () {
int num1, num2, num3, large;

[Code] ....

For some reason it keeps num3 as large.

View 5 Replies View Related

C++ :: Finding GCD Of N Numbers

Feb 14, 2014

I know how to write the GCD for one, two, three, four, and etc, numbers. But I cannot seem to find a way to write a code that does it for 'n' numbers.

That is, the user inputs a number 'n', which determines the size of a dynamic array. Then they are prompted to input the values for each of the elements in the array that will constitute the numbers the program is to find the GCD for.

This records the array:

for (int count = 0; count < n; count++) {
cout <<"Enter the numbers you wish to find the GCD for, for term" << count << ": ";
cin >> GCD_n[count];
}

Here is a code for finding GCD of three numbers:

cout << "This program finds the greatest common divisor of three numbers.
"
<< "Enter the first number:
";
cin >> a;

[Code] ....

How to proceed coding a program that finds the GCD of 'n' terms.

GCD_n[n] is the array that contains the numbers for which we need to determine the GCD for.

My main problem is with writing a code that tests the elements of the array containing the list of numbers in GCD_n[n], all at the same time, such that:

int n;
cout << "This program finds the greatest common divisor of n numbers.
"
<< "What is the total amount of numbers you want to find the GCD for?

[Code] .....

View 1 Replies View Related

C++ :: Finding Maximum Value In A Map

Jul 26, 2014

Suppose that a map is defined thus: map<sttring, int> mymap;

I wanna find k maximum values. Is there a way to find the maximum value in an efficient manner? Or else, How can I sort them and then find the k first elements?

View 1 Replies View Related

C++ :: Finding The Address Of A Bitfield

Aug 14, 2013

So I obviously can't take the address of a bitfield, but is there a way to get the address of the field holding the bitfield? What I'm trying to do is find the address of the parent field of a bitfield in a class. For example

Code:
class Foo
{
public:
int a;
int b : 4;
int c : 28;
[Code] ....

My goal is to get the offset address of the int storing c in class Foo. But offsetof uses the address of c, so I get a compile error since c is a bitfield. What I wanted as output from the above would be "4", since an int is 4 bytes (on my system). So the int holding both b & c starts 4 bytes from the start of the Foo class. Is there any way to do this in c/c++?

View 14 Replies View Related

C++ :: Finding Grid Of Mines?

Aug 8, 2014

Code: There is a rectangular grid of numbers. The grid has m rows and n columns. So it has m*n cells in total.The rows are numbered from 1 to m and the columns are numbered from 1 to n. The top most row has number 1, the row next to it has number 2 and so on. Similarly, the left most column has number 1, the column next to it has number 2 and so on. Each cell in the grid has a unique coordinate which is (x, y) where x is the row number and y is the column number of that particular cell.

Each cell in the grid has an integer in {0, 1, 2, 3, 4, 5, 6 ,7 ,8}. Number in cell (x,y) is number of mines in neighboring cells (cells have at least 1 common vertex with cell (x,y))

Your task is to find grid of mines, i.e display an m*n grid of numbers {0, 1} (cell (x, y) is 1 if there is a mine in cell (x, y)).

Input
First line of the input contains two space separated integers, m and n. Next m lines, each line has n numbers in {0, 1, 2, 3, 4, 5, 6 ,7 ,8}.

Output
A grid of numbers {0, 1}

View 4 Replies View Related

C :: Array Finding Position Of A Value?

Dec 24, 2013

So for a project I'm working on, I'm using an array and generating it's values randomly but unique. Currently I'm working on a 3X3 array and the generated values are in the range from 1-9. So I wrote a function that will tell me the position of the cell whose value is 9. This is the function I wrote:

Code: void Llogaritje1(int t[3][3],int &i, int &j){
int y,l;
for(y=0;y<3;y++){
for(l=0;l<3;l++){
if(t[y][l]==9){
i=y;
j=l;
break;
}
}if(t[y][l]==9) break;
}
}

But it doesn't work on all cells. Seems like at cells t[1][0] and t[2][0] the values that i and j take are 0 0 since when I print them after excecuting the function that's what it returns. I really don't understand why.

View 4 Replies View Related

C :: Finding The Minimum Value Of Array

Sep 9, 2013

I am trying to make my program read a bunch of numbers in an array to find its maximum and minimum. the program will ask the user to enter in as much number as possible until they enter a non number/letter. i got my program to find the maximum value but the program couldn't read the minimum value. it always says zero. also everytime i enter the number 0, the program will just finish its loop statement. If i typed in a negative number, it'll read the negative number as its minimum.

Code:
#include <stdio.h>
int main()
{
//-------variables------------------
double list[1000]; // can hold 1000 items
int i;
char letter;
int max = list[0];
int min = list[0];

[Code] ....

View 5 Replies View Related

C :: Finding Diagonals Of Array?

Apr 11, 2014

Most of this program is working correctly, however when I get to the part on lines 70 to 78 to try and use the function on lines 103 to 113 to find out each diagonals value and then print each one back. But when this runs it only returns the value for [0][0] for each run through the loop and I'm not really sure why. I know its probably something simple but I'm just missing it,

Code:
1 #include<stdio.h>
2 #include<stdlib.h>
3 #include<time.h>
4 #define MAX 100
5
6 void display_menu();
7 int check_option(int);

[Code]...

View 4 Replies View Related

C :: Program Finding Max Of Graph

Oct 29, 2013

this is my first year programming, and in my class, each week we have to write a program. last week we wrote a program in c that made random value point and made a graph of the random points that continued on forever. this week, we have to use statistical functions to find the sum, mean, max, and min of the graph. below is the code i have so far.

Code:

#include <stdlib.h>
#include <strings.h>
#include <stdio.h>
#include <stdbool.h>
#include "SwinGame.h"

[code]....

so, as you can see from the code, the parts i need are finding/ coming up with a function to find the max min sum and mean of the functions.

View 7 Replies View Related

C :: File I/O Finding Max And Min Numbers

Dec 4, 2013

My question is to write a complete program that will search a file of numbers(numbers.txt) for the smallest and largest numbers and then write the values to the screen using a single pass through the file. File only contains type int and holds at least one int. My questions are am I reading in the first number correctly? Where would I read in the second number to compare to the current max and min?

Code:

#include <stdio.h>
#include <stdlib.h>
int main(int argc, char * argv[])
{
FILE *fin;
fin = fopen("numbers.txt", "r");
//check to make sure file opened
if(fin == NULL)
}

[code]...

View 11 Replies View Related

C :: Finding Two Largest Numbers

Mar 25, 2013

I'm trying to find the two largest numbers out of ten. I've re-done this problem several times and it still doesn't work.

Code:

#include <stdio.h>
int main(void) {
float number;
float largest;
float secondLargest;
float counter;
float temp;
}

[code]....

View 9 Replies View Related

C :: Finding Mode Of Array

Mar 20, 2014

I've been trying for over an hour to think of the logic to find the mode of an array.I left out code for initializing the arrays, but all the values in the array are between 0-9. Check out my code below.

Code:

int mode( int array[], int size ) {
int i;
int count;
int max = 0;
int num = 0;
int mode;

[code]....

View 7 Replies View Related

C :: Finding Out Neighbors Of Triangle

Mar 2, 2015

I need to find out neighbors of a triangle and loop it over entire unstructured grid. How to do it?. Cell numbers are random so I am unable to loop over all cells.

View 9 Replies View Related

C++ :: Finding Words In A File

Oct 21, 2014

This function buildTree that reads an text input (contained in the file named in argv[1]). Then, I am opening the file, reading character by character, if there is a new line ("if (token == ' ')") keep track of this line number and store it in a vector to access it later. Next it breaks it into a sequence of words (using any character other than a digit or an alphabetical symbol as the terminator). This is where I'm getting an error. I am then trying to add each character to a string and then when the token is a digit or an alphabetical symbol, then push the string into a vector so I can access it later. Is my logic right? error when pushing each word into a vector.

BinarySearchTree buildTree (char *argv[]){
ifstream file;
vector<char *> V;
int line = 0;

[Code]....

View 2 Replies View Related

C++ :: Finding Angle From 3 Points

Nov 10, 2013

I am making a game and I am trying to rotate an image so that it is always pointing at the player. I have two lines, the first point of both of them is on the image and the second point of one line is on the last position of the player, and the second point of the other one is on the current position of the player. To rotate the image I need to get the angle between the two lines. how I can get that angle with only the points from the lines?

View 7 Replies View Related

C++ :: Finding The Average Of Array

Apr 16, 2013

I am attempting to write a program that takes a number(picked by the user) of test scores in an array then calculates the average and outputs the number of passed and failed tests.

On a side note I am attempting to use array notation in the main function and pointer notation in the other functions

#include<iostream>
#include<iomanip>
using namespace std;
int numScores;
int counter = 0;
double *scores;
//Function Prototypes

[Code]...

View 3 Replies View Related

C++ :: Finding Maximum Value In A Vector

Nov 12, 2014

This is part of my main code that is giving me compiler issues.

//Find max value
max = max_element(vecTemperature.begin(), vecTemperature.end());

I keep getting an error saying "[Error] cannot convert '__gnu_cxx::__normal_iterator<int*, std::vector<int> >' to 'int' in assignment"

View 2 Replies View Related

C++ ::  finding Max Value From A List Of 10 Values?

Jan 26, 2013

i am trying to find the max value from a list of 10 values. here i have stored the double values for prices of items in numVal.There are 10 values in numVal i would like to find the max and min value of these numbers. getPrice(1) returns the ten double values.

for(int i = 0; i < store.size(); i++) {
double numVal = this->store[i].getPrice(1);
}

View 2 Replies View Related







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