setting output width for values if a function

Okay, I have most of the code for this done, but something that I just can't get is how to separate the different values given out by a function. For example, I made a program with a function that is supposed to give out the values it has found in row and column form. For example, If the function outputs values of 2.0, 1.7 and 0.0, it should print out like this:

2.0 1.7 0.0


but for me, its coming out like this
0.0
1.7
2.0

How could I use the iomanip and setw() to do this, if at all? A nudge in the right direction would be more appreciated than a solution without explanation. Thank you!
You are saying about something. Can you give us code or a function or anything? According to that you have written, I can advise you only: cout << 2.0 << " " << 1.7 << " " << 0.0 << endl;

of course. Here is the code I have written. I think the formatting problem is within the second nested for loop (the one for y):

//File name:
//Created by:
//Created in:

#include <iostream>
#include <iomanip>
#include <cmath>

using namespace std;

double fun (int x, int y);

int main ()
{
int t(0);


cout << "Enter the number of table rows:";
int x;
int y;


while (cin >> t)
{

for (x= 0; x <= t-1 ; x++)
{
for (y= 0; y<=x; y++)
{
cout.precision(1);
cout.setf(ios::fixed);
cout << setw(2)<< fun(x,y)<< setw(2)<< endl;








}





}


}
















return 0;
}


double fun (int x, int y)
{
double f(0.0);

f = sqrt(x*x-y*y);


return (f);
}

Topic archived. No new replies allowed.