4 Replies - 287 Views - Last Post: 25 October 2013 - 12:12 PM Rate Topic: -----

#1 siti_amirah  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 1
  • Joined: 25-October 13

array 2 dimesional

Posted 25 October 2013 - 11:10 AM

hello I want to ask about this code
I tried to make this code and I want the output came out with this 2.30;
2.75
3.20
2.95
1.75
2.10
2.60
3.50
I hope somebody can help me!


#include<stdio.h>
int main()
{
	float disk [2][4];
	
	int column, row;

	disk[0][0] =2.30 ;
        disk[0][1] = 2.75;
	disk[0][2] = 3.20;
	disk[0][3] = 2.95;
	disk[1][0] = 1.75;
	disk[1][1] = 2.10;
	disk[1][2] = 2.60;
	disk [1][3] = 3.50
	for (row=0; row<2; row++)
	{
		for (column=0; column<4; column++)
		{
		printf ("RM.2f \n", disk[column][row]);
		printf ("\n");
		}
	}
	return 0;
}

This post has been edited by jimblumberg: 25 October 2013 - 11:30 AM
Reason for edit:: Added missing code tags, please learn to use them properly.


Is This A Good Question/Topic? 0
  • +

Replies To: array 2 dimesional

#2 mojo666  Icon User is offline

  • D.I.C Addict
  • member icon

Reputation: 352
  • View blog
  • Posts: 771
  • Joined: 27-June 09

Re: array 2 dimesional

Posted 25 October 2013 - 11:29 AM

It would help to tell us exactly what issue you are having. However, I did notice that disk [1][3] = 3.50 is missing the semi colon at the end.
Was This Post Helpful? 0
  • +
  • -

#3 Skydiver  Icon User is offline

  • Code herder
  • member icon

Reputation: 3576
  • View blog
  • Posts: 11,126
  • Joined: 05-May 12

Re: array 2 dimesional

Posted 25 October 2013 - 11:47 AM

And line 20 looks wrong as well.
Was This Post Helpful? 0
  • +
  • -

#4 .Aaron  Icon User is offline

  • Rock, paper, scissors, lizard, Spock
  • member icon

Reputation: 62
  • View blog
  • Posts: 2,895
  • Joined: 04-August 09

Re: array 2 dimesional

Posted 25 October 2013 - 11:48 AM

Well he doesn't have anything to stop the console closing before he can ever see the output, so, just in case that's the problem...

siti_amirah, and #include<iostream> up with you're other include, and then you can place std::cin.get(); after everything is done printing. That will make it so that the window won't close until you hit enter.

@ Skydiver, Yea, it's not printing the values in the disk array link that. I just used cout back when I was using C++ so aside from suggesting to switch to that output method I'm not sure what to tell him about that one, aside from maybe putting it and the text he has before it into a string before hand and then just printing the string.

This post has been edited by .Aaron: 25 October 2013 - 12:12 PM

Was This Post Helpful? 0
  • +
  • -

#5 Skydiver  Icon User is offline

  • Code herder
  • member icon

Reputation: 3576
  • View blog
  • Posts: 11,126
  • Joined: 05-May 12

Re: array 2 dimesional

Posted 25 October 2013 - 12:12 PM

There are 2 issues with line 20.
1. You need to use a format specifier indicating the type and formatting you want for your array elements.
2. It looks like you have row and column swapped.
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1