Hello.. i've this HW.. i did what i can do.. but there were some errors that i couldn't fix.. and one point i dunnu how to do it which is change negative variables to positive ones?? can someone tell me how to code that?

here is my code:

#include <iostream>
using namespace std;




int main ()
{
	int ARR [2][3];
	int i,j;

	cout<<"You are going to fill a 2x3 array,"<<endl
		<<"meaning 2 rows and in each row 3 items."<<endl<<endl
		<<"Please enter 3 positive values separated by a space for row0:";

	for(int i=0;i>=1;i++)
	{
	cin>>ARR [i];
	}


	cout<<"Please enter 3 negative values separated by a space for row1:";
	for(int j=0;j>=2;j++)
	{
	cin>>ARR [j];
	}


	cout<<"Array elements after filling array are:"
		<<"_________________________________________"<<endl<<endl

		<<"Row#0:"
		<<ARR [i]
		<<endl

		<<"Row#1:"
		<<ARR [j]
		<<endl<<endl

		<<"Array elements after changing negative array values to positive values are:"
		<<"___________________________________________________________";

		

		cout<<"Row#0:";
		for (int i=0;i>=1;i++)
		{
		cout<<"The array element:"<<i;
		}

		cout<<"Row#1:";
		for (int j=0;j>=2;j++)
		{
		cout<<"The array element:"<<+j;
		}


return 0;
}

Attached is the desired output.

Attachments 3a1.jpg 31.7 KB

>i dunnu how to do it which is change negative variables to positive ones??

I think you mean the 'absolute value', take a look at this:

int a = -5; // a contains a negative value
a = abs(a); // a now contains 5 instead of -5

>but there were some errors that i couldn't fix

Well, you declare ARR as a two dimensional array, so this code is invalid: [B]cin>>ARR [i];[/B] (you always have to specify two subscripts if you're dealing with a two-dimensional array)

If your intention was to fill the first column of that array, then you could do the following: [B]cin>>ARR [i][0];[/B] :)

OOh.. yeah right.. i didn't know that i shoud do that..
i did it now. I got 1 succeeded.. but with warnings and not the desired output yet..
this is the last code

#include <iostream>
using namespace std;




int main ()
{
	int ARR [2][3];
	int i,j;

	cout<<"You are going to fill a 2x3 array,"<<endl
		<<"meaning 2 rows and in each row 3 items."<<endl<<endl
		<<"Please enter 3 positive values separated by a space for row0:";

	for(int i=0;i>=1;i++)
	{
	cin>>ARR [i][0];
	}


	cout<<"Please enter 3 negative values separated by a space for row1:";
	for(int j=0;j>=2;j++)
	{
	cin>>ARR [j][0];
	}


	cout<<"Array elements after filling array are:"
		<<"_________________________________________"<<endl<<endl

		<<"Row#0:"
		<<ARR [i][0]
		<<endl

		<<"Row#1:"
		<<ARR [j][0]
		<<endl<<endl

		<<"Array elements after changing negative array values to positive values are:"
		<<"___________________________________________________________";

		

		cout<<"Row#0:";
		for (int i=0;i>=1;i++)
		{
		cout<<"The array element:"<<i;
		}

		cout<<"Row#1:";
		for (int j=0;j>=2;j++)
		{
		cout<<"The array element:"<<+j;
		}





return 0;
}

ops sorry.. this is the last code.. am not sure if i did what u told me right.. abt the absolute value..

#include <iostream>
using namespace std;




int main ()
{
	int ARR [2][3];
	int i,j;

	cout<<"You are going to fill a 2x3 array,"<<endl
		<<"meaning 2 rows and in each row 3 items."<<endl<<endl
		<<"Please enter 3 positive values separated by a space for row0:";

	for(int i=0;i>=1;i++)
	{
	cin>>ARR [i][0];
	}


	cout<<"Please enter 3 negative values separated by a space for row1:";
	for(int j=0;j>=2;j++)
	{
	cin>>ARR [j][0];
	}


	cout<<"Array elements after filling array are:"
		<<"_________________________________________"<<endl<<endl

		<<"Row#0:"
		<<ARR [i][0]
		<<endl

		<<"Row#1:"
		<<ARR [j][0]
		<<endl<<endl

		<<"Array elements after changing negative array values to positive values are:"
		<<"___________________________________________________________";

		

		cout<<"Row#0:";
		for (int i=0;i>=1;i++)
		{
		cout<<"The array element:"<<i;
		}

		cout<<"Row#1:";
		for (int j=0;j>=2;j++)
		{
			
			j = abs(j); 
			cout<<"The array element:"<<j;
		}





return 0;
}

>ops sorry.. this is the last code.. am not sure if i did what u told me right.. abt the absolute value..

Well, does it give the expected output? Then you're probably right, otherwise you've done something wrong :)

Edit:: You've made some logical mistakes in your code, take a good look at when you're filling row 1 and row 2?
The subscripts are wrong... (Change it also when outputting the array to the screen)

Ugh,,, why does this window keep appearing.. it says the variabla j is being used without bein initialized !! IT is initialized !
and am getting this as a compiler message:
1>------ Build started: Project: HW 12, Configuration: Debug Win32 ------
1>Linking...
1>Embedding manifest...
1>Build log was saved at "file://c:\Users\fofa\Documents\Visual Studio 2005\Projects\HW 12\Debug\BuildLog.htm"
1>HW 12 - 0 error(s), 0 warning(s)
========== Build: 1 succeeded, 0 failed, 0 up-to-date, 0 skipped ==========

Ugh,,, why does this window keep appearing.. it says the variabla j is being used without bein initialized !! IT is initialized !
and am getting this as a compiler message:
1>------ Build started: Project: HW 12, Configuration: Debug Win32 ------
1>Linking...
1>Embedding manifest...
1>Build log was saved at "file://c:\Users\fofa\Documents\Visual Studio 2005\Projects\HW 12\Debug\BuildLog.htm"
1>HW 12 - 0 error(s), 0 warning(s)
========== Build: 1 succeeded, 0 failed, 0 up-to-date, 0 skipped ==========

According to your compiler's message your code is compiling perfectly...

it does.. but it's not running perfectly..
when i run the program.. it's taottaly different than the output that is attached here !! I dunnu why.. keeps getting me a window that says variable j being used without being initialized :S !

>keeps getting me a window that says variable j being used without being initialized !

Ah, now I understand! That's because you declared variable j, but you don't give it a start value (= you don't initialize it), you may not assume that j will get the value zero automatically, but you can specify it like this:
Change line 10 of your code to: [B]int i = 0, j = 0;[/B]

ok i did that.. but still it's not the output..
there's no space for the user to enter the numbers.. the program runes by it self and doesn't allow the user to enter any numbers..

i guess theres smthn wrong with my code.. but i don't know what is it :S

The code to get input from the user is wrong, you should rather use:

cout<<"Please enter 3 negative values separated by a space for row1:";
[B]for(int i = 0; i < 3; i++)
        cin >> ARR[1][i];[/B]

(this applies to both: the positive and the negative values)

BTW, This doesn't work if you want to display an element of the array: cout<<"The array element:"<<i;

there are several things still wrong with your code.

take a look at this

for(int i=0;i>=1;i++)
{
    cin>>ARR [i][0];
}

here i is initialized to 0 but the for loop condition segment requires a value of i that is greater or equal to 1. this for loop wont even run through once.

instead try using

for(int i = 0;i<3;i++)
{
    cin>>ARR[0][i];
}

this will hit column 0-2 in for 0.
There is a similar problem with the rest of your for loops.

if all you have to do is output the absolute value of the second row and all the number that go into the second row are negative then you sould use a simple cout line.

for(int j=0;j<3;j++)
{
    cout<<"The array element: "<<ARR[1][j]*-1;
}
This article has been dead for over six months. Start a new discussion instead.