Write a program to input the following values into an array named prices:
10.95, 16.32, 12.15,8.22,15.98,26.22,13.54, 6.45, 17.59. Then you should
print out the values.
Use the format:
10.95 16.32 12.15
8.22 15.98 26.22
13.54 6.45 17.59
I am just so lost on how to make the rows and columns, arrays I have no problem with.
int x;
float prices[9];
for(int count=0;count<9;count++)
cin>>float[x];
right? Then I gotta put them into rows and columns any ideas?
float prices[9];
for (int i=0; i<9; i++)
cin >> prices[i];
for (i=0; i<9; i++)
{
cout << prices[i];
if ((i+1) % 3 == 0) cout << endl;
}
I changed the count variable to i because i is shorter to write and don't want you having confusion with similar looking cout & count
Please also note the line cin >> prices[i] as opposed to cin >> float[i].
The line: if ((i+1) % 3 == 0) cout << endl;
will test if the remainder of (i+1) divided by 3 is zero, ie is i+1 a multiple of 3.
If so we skip to next line which give your your next row after 3 columns was printed.