i keeps getting error i going to break my head to solve this problem =.=

what i am doing is using the a[3][3] to minus 128 but seem i get the problem in minus

#include <iostream>
#include <iomanip>
#include <cmath>
#include <cstdlib>
using namespace std;

double shifted_block(double array[3][3]);


int main ()
	{
		
// input number in 3X3 array
		
	double a[3][3];
	
	double zero_zero;
	*(a+0)[0] = zero_zero;
	double zero_one;
	*(a+0)[1] = zero_one;
	double zero_two;
	*(a+0)[2] = zero_two;
	
	cout << "Enter 1st row" << endl;
	cin >> zero_zero >> zero_one >> zero_two;
	
	
	double  one_zero;
	*(a+1)[0] = one_zero;
	double one_one;
	*(a+1)[1] = one_one;
	double one_two;
	*(a+1)[2] = one_two;
	
	cout << "Enter 2nd row" << endl;
	cin >> one_zero >> one_one >> one_two;
	
	
	double two_zero;
	*(a+2)[0] = two_zero;
	double two_one;
	*(a+2)[1] = two_one;
	double two_two;
	*(a+2)[2] = two_two;
	
	cout << "enter 3nd row" << endl;
	cin >> two_zero >> two_one >> two_two;
	
	
	cout << zero_zero << " " << zero_one << " " << zero_two << " " << endl;
	cout << one_zero  << " " << one_one  << " " << one_two  << " " << endl;
	cout << two_zero << " " << two_one << " " << two_two << " " << endl;

//display out

	
				
	cout << shifted_block(zero_zero) << endl;
	
	
	
	return 0;
		
	}

// to minus 128 of the value input
		
double shifted_block(double array[3][3])
{
	
		
	for (int countrow = 0; countrow < 3; countrow++) {
		
    for (int countcolumn = 0; countcolumn < 3; countcolumn++){
	    
    return array[countrow][countcolumn] = array[countrow][countcolumn] - 128;
         
                
    }
    
}





}

Firstly, this is not a code snippet, code snippets are for things like I have a tried and true function that might benefit the community (or many other related matters but not in general homework).

I'm not super sure why you couldn't assign directly to a[3][3] from input.

cin>> a[0][0] >>a[0][1] >> a[0][2];

I also don't know why you are passing in zerozero to your function as it in and of itself is not a pointer to your whole array. Just pass in a . In addition you are only performing your function calculation on 1 single element before you return. If you want to return an entire array, you could just pass a by reference instead of returning a double (in reality you are passing it by reference here but just not doing anything with it back in main)

man sorry to ask a question on your question forum but what does this do:

double zero_zero;
	*(a+0)[0] = zero_zero;
	double zero_one;
	*(a+0)[1] = zero_one;
	double zero_two;
	*(a+0)[2] = zero_two;

question 1:
what is *(a+0)[0] supposed to be?
do you mean a[0][0]?
question 2:
why are you setting this *(a+0)[0] = zero_zero;
when zero_zero was just declared and has no value attached to it?

if I knew what that ment I could understand your code probably 100x better than I do right now. Thanks cya.

He/she is addressing the 3x3 array members by pointers and setting them to an intermediate variable so that when the input is written to said intermediate it will be written into the array. I agree with your point I don't know what prohibits setting a[0][0] to a value directly, etc.

Oh now I see what that does thanks jonsca that makes more sense now lol. I have a new question now though.

For this piece of code:

double  one_zero;
	*(a+1)[0] = one_zero;
	double one_one;
	*(a+1)[1] = one_one;
	double one_two;
	*(a+1)[2] = one_two;

can you have *(a+1) like this or do you to do something like this:

double  one_zero;
	*(a+sizeof(double))[0] = one_zero;
	double one_one;
	*(a+sizeof(double))[1] = one_one;
	double one_two;
	*(a+sizeof(double))[2] = one_two;

because I thought that using the *(a) brings you to a's memory location so if you are going to move down to the next row of a multi dimensional array you would need to move down the size of a double not just 1. Unless putting 1 there does move it down based on type and I might be completely wrong.

hrmmmmmz actually now that I think about how I think the memory is set out for this I would think you would have to access it like this :

double  one_zero;
	*(a+3*sizeof(double))[0] = one_zero;
	double one_one;
	*(a+3*sizeof(double))[1] = one_one;
	double one_two;
	*(a+3*sizeof(double))[2] = one_two;

where you multiply the value of the double by 3 because there are 3 doubles before it from the first row of the array.

Thanks in advance for anyone that can help clear up what the +1 does if it is actually right.

I may be incorrect, but since they are multidimensional arrays, the (a+i) value should be a pointer to a pointer (to a dereferenced element with the []) so it's a pointer indicative of the 0th, 1st, or 2nd "row" and then the given index in [] should be the offset into the that row.

And the reason you don't need the sizeof is as you said, the array has been declared with a specific datatype.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.