C :: Subtracting One Column In 2D Array From Another?

Oct 18, 2013

I have a 2d array where I manage donations and requests for different foods. I output a menu to the user who picks the options to either make a donation, make a request, fulfill a request, or print a status report of all the donations and requests. What I'm having trouble with is the fulfilling requests option. When the user picks fulfill requests that means that the donations are supposed to be subtracted from the requests. For example if there are 10 donations for grains and 15 requests for grains then after picking fulfill request there should be 0 donations for grains and 5 requests for grains but I don't know how to make the program do that since the values are in a 5 row by 2 column array. The five rows correspond to the five foods and the two columns correspond to donations and requests, respectively. Here's my code so far. Just disregard everything but the third case.

Code:
#include <stdio.h>int main(){
int foodbank[5][2]= {
{0,0},
{0,0},

[Code]....

View 6 Replies


ADVERTISEMENT

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 :: Sorting 2D Array By Column

Oct 24, 2013

i have a matrix containing a lot of points and each point has its coordinates x and y. That is a nx2 size array. I want to sort it according to the first column ascending, with x coordinates. For points that have the same x coord i would like to sort according to y coord. Here is what i did and i cannot get a good result.

Code:

#include <stdio.h>
#include <stdlib.h>
int main(){
int a[5][2] = {{1,0}, {4,2}, {2,4}, {8,6},{4,8}};
int temp=0;
int i=0;
int j=0;

[Code]...

View 4 Replies View Related

C++ :: Subtracting ASCII Hex Value In 64 Bit Hex Value

Mar 31, 2015

I have some ascii characters in a char variable.ex - char buf[100]="ab*(z&";

So each of the char in that char array will have some hex value.ex- *'s hex value is '2a'.

And I have a long long int variable in which there is a 64 bit hex value.

ex- long long int k=0x0000888888888888;

Now i want to subtract the char buff's hex value in k. How to accomplish it.

That is 0x0000888888888888
- 0x000061622a287a26
= 0x000027265e600e62 (final result in a buffer or a long variable is okay)

Later i want to reverse the result as 26e006e56272.It should be stored in a variable such that i should be able to access each byte from it(ex- '72'(last 2 hex digits))

View 1 Replies View Related

C++ :: Pointer With Array - Calculating Row And Column Sum

Jul 20, 2014

I have two doubts in the following code,the doubts are marked..PLs note that the following code is correct .This is a program to read 2d array using pointer ()i.e Dynamic array ,to calculate its rowsum and column sum and display this array along row sum and column sum.

#include<iostream.h>
#include<conio.h>
void main() {
clrscr();
int *Val,*Rsum,*Csum;
int MaxR,MaxC,i,j;

[Code] .....

View 2 Replies View Related

C++ :: Subtracting Value From 2 Integers In 2 Classes

Feb 11, 2013

I have 2 integers, both in 2 seperate classes in 2 seperate files. I have main.cpp, test_01.h, Test_01.cpp, Player.h and Player.cpp. I ahve a function which takes an integer (a) as a parameter (from Test_01.h and Test_01.cpp). a sets another integer (attackPower) from the same class equal to a. The integer (health) in the other class (Player.h and Player.cpp), is then equal to health -= attackPower. But instead of giving me the right answer 75 (health = 100 and a is set to 25 when i call the function) it gives me the answer.

main.cpp

#include <iostream>
#include "Test_01.h"
#include "Player.h"
using namespace std;
int main() {
Player p;
Test_01 t;

[Code] ....

View 2 Replies View Related

C++ :: Subtracting Values In A Vector?

Jun 9, 2013

I want to add this piece of code to a project. I have created a vector from values entered by a user. I want to then subtract each value from each other from the beginning to the end. For example if a user enters 10,4,3 the program will subtract the values in that order 10 - 4 - 3 and output 3 as the solution. I figured how to do it with addition but can't get it to output for subtraction.

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

[Code].....

View 5 Replies View Related

C :: Finding The Most Occurring Element In Column 1 Of 2D Array

Oct 7, 2014

This is for a 2-d array, but if i understand how to do it for a 1-d array, I can do it for a 2-d. So to keep it simpler, I will just pretend its for a 1-d array. I am working on a project where i must enter the month number of a storm and then tell the user which month had the most storms. So I have an array and the user determines the size of it by entering the number of storms. Then, using a for loop, the user enters the month number for each storm and the data is used to fill the array. This is to be used in a part of a much larger piece of code. I made a sample code below to mimic what i want to do:

Code:
#include <stdio.h>
#include <stdlib.h>
int main(int argc, char *argv[]) {

/*Declare variables, i is a counting index used in for loop if necessary*/

[Code] ....

I believe this involves making some temporary array but where to start ....

View 2 Replies View Related

C++ :: Subtracting Pixel Values From Two Different BMP Files

Dec 30, 2014

I would like to subtract one image from another to get something like "differential picture" (i am not sure whether the name is correct). I've managed to read the FILEHEADER and FILEINFOHEADER of bitmap. I will subtract 24-bit bmp files only. However i can't understand the structure of this file. So far my code looks like this. Any example of at least copying one bmp file to a new one? This example would be useful, because subtracting will be simillar, instead of copying the pixel value i will just put abs(value1-value2) in the output.

Code:

// ConsoleApplication1.cpp : Defines the entry point for the console application.
#include "stdafx.h"
#include <iostream>
#include <fstream>
using namespace std;
struct BITMAPfileHEADER {

[Code] .....

View 4 Replies View Related

C/C++ :: Subtracting Area Of Two Circles From A Rectangle

Mar 31, 2015

[URL] .... This is what I have so far, and it isn't incorrect, but how to improve this or make it more accurate?

// subtracting the area of two circles from a rectangle
#include <iostream>
using namespace std;
int main() {
cout << "This program is designed to calculate the area of a rectangle, to exclude the area of 2 circles that have been placed inside of the rectangle." << endl << endl;

[Code] .....

View 12 Replies View Related

C++ :: Adding And Subtracting Integer Arrays?

Apr 23, 2013

I am currently working on a program that uses a class to store integer arrays. I have most of the code done, but I am having trouble on the main.cpp part of my program. The program should display this:

OBJ 1:
2 3 4
OBJ 2:
1 4 -2
Addition:
OBJ 1 =
3 7 6
Subtraction:
OBJ 1 = 1 -1 6

But when I run and compile my program, this is what I get:

OBJ 1:
2 3 4
OBJ 2:

ADDING:
OBJ 1 =
4 6 8
Subtraction:
OBJ 1 =

Here is my current main.cpp:

Code:
#include <iostream>
#include "SafeArray.h"
using namespace std;

[Code].....

View 3 Replies View Related

C :: Reading Values From File To First 2 Columns Of 2D Array / Assigning 0 To 3rd Column

Apr 4, 2014

I am attempting to read values from a file into a 2d array temp[31][2] (31 rows, 3 columns).I only want the values from the file to be read into the first two columns.I believe I am accomplishing that but when I go to print the array, I expect the first two columns to have the file data and the third column to have all zeros. The third column, however is printing such that the value is the next row/first column.

I'm not sure for instance why on the bottom loop for line 1 it doesn't print:

temp[0][0] temp[0][1] temp[0][2] 20 49 0 It instead prints: 20 49 1

Code:

#include <stdio.h> Code: #include <math.h>
FILE *inptr;
int main() {
int temp[31][2] = {0}, tempavg[31][2] = {0};
int i, j, k, sum;
inptr = fopen("ProgrammingProject14.txt", "r");

[code]....

View 8 Replies View Related

C :: Unable To Save A Column Element Into Dynamically Memory Allocated Array

Mar 3, 2014

I am trying to store each value of a column from a text file into an dynamically allocated array, which needs to be globally declared for further usage in the program.The input textfile contains the following:

34932 13854 13854 2012-01-07
172098 49418 53269 2012-01-07

I have written the following code:

Code:

#include<stdio.h>
#include<stdlib.h>
#include<string.h>
int main()
}

[code]....

The commented printf line gives the entire values of the column, which proves that the file is correctly being read.But on compiling this program I get both compiler warnings and finally segmentation fault.

View 5 Replies View Related

C++ :: How To Sum Row And Column Of 2D Arrays

Apr 11, 2013

For example If I have the following . How would I sum each row and column ??

For example

1 2 3 4 5
0 1 3 8 9

View 6 Replies View Related

C++ :: Iterating Over Either Row Or Column?

Jul 3, 2014

Suppose I want to represent an apartment building in terms of floors and rooms with a single data object. Each floor has the same number of rooms at any given time. During the course of the program, I will need to change the number of floors occasionally and will need to change the number of rooms on each floor occasionally. (Don't worry about the building permits needed to do this.) Now, I also want to be able to iterate over either each floor (think "row") or each room (think "column"). For example, I might want to program the equivalent of "Johnson, go fix all the front doors on the 8th floor" or the equivalent of "Johnson, go fix all the front doors to room B on each floor". (Yeah, I know, for the latter I could iterate over each floor and then access room B but that doesn't feel as "clean" as being able to iterate over a separate room/column.)

View 7 Replies View Related

C++ :: Row And Column Index?

Dec 16, 2013

If i have current index and row/columns count how do i get on which row and on which column index is individually?

This is what i have tried, but column index is incorrect:

#include <iostream>
int main()
{
int rows = 5;
int colm = 6;
int inx = 12;
int rowInx = inx % rows;
int colInx = inx % colm;
std::cout << "row: " << rowInx << std::endl;
std::cout << "col: " << colInx << std::endl;
return 0;
}

View 4 Replies View Related

C/C++ :: Iterating Over Either Row Or Column?

Jul 31, 2014

Suppose I want to represent an apartment building in terms of floors and rooms with a single data object. Each floor has the same number of rooms at any given time. During the course of the program, I will need to change the number of floors occasionally and will need to change the number of rooms on each floor occasionally. (Don't worry about the building permits needed to do this.)

Now, I also want to be able to iterate over either each floor (think "row") or each room (think "column"). For example, I might want to program the equivalent of "Johnson, go fix all the front doors on the 8th floor" or the equivalent of "Johnson, go fix all the front doors to room B on each floor". (Yeah, I know, for the latter I could iterate over each floor and then access room B but that doesn't feel as "clean" as being able to iterate over a separate room/column.)

View 2 Replies View Related

C++ :: Sort Particular Column Of CSV File

Apr 6, 2013

I need sorting a particular column (column 1) of a .cvs file (the file has 10 columns) by alphabetic order. How I can accomplish this ?

View 1 Replies View Related

C++ :: Salary Column Output Zero

Feb 21, 2014

void calcWeeklyPay(double empData[][COLS], const int count) {
double wage;
double hour;
int row;
for (row = 0 ; row < count; row++); {
hour = empData[row][0];
wage = empData[row][1];

[Code] ....

I'm really stuck on this problem...Why is it in my salary column all it outputs its 0? How would i fix this ?

View 2 Replies View Related

C++ :: Reference To Column Is Ambiguous

Feb 18, 2014

I'm using GCC 4.8.1 and I want to implement a XML parser using TinyXML and port it to AngelScript

Now, it says: reference to 'Column' is ambiguous

I've declared a class called xml_parser and I've added everything of tinyxml as it's public member when I call Column(), and also Row(), it give's this error. what should I do?

This is it's code:

xml_parser.hpp:
#ifndef AGK_XML_PARSER_H
#define AGK_XML_PARSER_H
#define TIXML_USE_STL
#include <tinyxml.h>

[Code] .....

View 16 Replies View Related

C++ :: Matrix - Remove Row And Column

Jul 11, 2013

I suppose to have the following matrix

A). I want to remove a generic row and column. For instance the second row and column, then I get
B). How can I realize it in C?How to do.

A) B)
a00 a01 a02
a00 a02
a10 a11 a12a20 a22
a20 a21 a22

View 2 Replies View Related

C# :: How To Get Column Names From Db3 File

Oct 2, 2014

I have .db3 file, and he has 14 tables,and every table has certain number of columns. Example i have table called "BASIC_INFO" and that table has columns "First Name", "Last Name" and "Age".

How can i get name of table and name of every column,so if i some day add column "Male" i get name of this column too. I need first to calculate number of columns,put that in some integer, and then for example create string array which will contain : array[0] = "First Name" ,array[1] = "Last Name"...

SQLiteConnection myConn = new SQLiteConnection("Data Source=" + DB3Path + ";Version=3;New=False;Compress=True;");
//string query = "Select * From " + DB3Path + ".INFORMATION_SCHEMA.COLUMNS";
string query = "Select * From BASIC_INFO.INFORMATION_SCHEMA.COLUMNS;";
SQLiteCommand sqCommand = new SQLiteCommand(query);

[Code] ....

I tried this too:

string query = "select * from INFORMATION_SCHEMA.COLUMNS"
+ "where TABLE_Name='BASIC_INFO'"
+ "order by ORDINAL_POSITION;";
string query = "SELECT TOP 0 * FROM BASIC_INFO";

View 2 Replies View Related

C# :: Grabbing Column From More Than One Table

Oct 18, 2014

I am writing a code in which i need to grab a column from a variety of tables. So basically there are 10 tables in which they hey have the same columns inside of them (Submitted and Amount). I need to grab the amount column from all the tables. What would be the c# sql command for that.

View 5 Replies View Related

C# :: Each Column With Different Datasource In GridView

Oct 7, 2014

I have question regarding Gridview.

Can i set each column in Gridview with different Datasource ? for example I create Gridview with 3 column , can I set each column with different datasource ?

View 2 Replies View Related

C# :: DataGridView CheckBox Column

Apr 24, 2014

I cannot check the checkbox in my datagridview.

Here is my code.

First, I added a checkbox column.

private void addCheckBoxColumn() {
DataGridViewCheckBoxColumn checkColumn = new DataGridViewCheckBoxColumn();
checkColumn.Name = "clmCheck";
checkColumn.HeaderText = "";
checkColumn.Width = 100;
checkColumn.ReadOnly = false;
dgv1.Columns.Add(checkC

[Code] ....

View 4 Replies View Related

C# :: Link Combobox With SQL Column

Oct 19, 2014

When I try to link combobox with sql column i get error !!

void comfunction() {
string constring = "Data Source=LC-VAIO\SQLEXPRESS;Initial Catalog=sample1;Integrated Security=True";
string query = "select * from tbltest";
SqlConnection cn = new SqlConnection(constring);
SqlCommand cmd = new SqlCommand(query,cn);
SqlDataReader dreader;

[Code] ....

I got error from "string sname = dreader.GetString("name"); "

And this how i try to link it...

View 9 Replies View Related







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