Can't get my loop to work

I'm working on an program that requires an input of both an initial and final value of x. It then creates creates a table with 4 rows and 3 columns. The first column is x, with four rows of evenly spaced values from x initial to x final. The second column is sin(x), and the third column is cos(x). I am using a for loop to create this table but I can't seem to get it to work. Here is the for loop I am attempting.

1
2
for(x=xi;xi<=xf;x+=dx)
      cout<<x<<setw(15)<<sin(x)<<setw(15)<<cos(x)<<endl<<endl;


I set dx as (xf-xi)/3 which is the step between the 4 evenly spaced values of x.
The output comes up with an endless loop with xi as the only x value.

I am thinking that I might have to use a nested for loop, but I'm not really sure.
A hint in the right direction would be much appreciated.
Thanks for your time.
yes, try to use a nested for loop to create the table
I've been trying to create a nested for loop but I'm not sure of what criteria to use for each one.
use x in middle not xi
1
2
for(x=xi; x<=xf; x+=dx)
      cout<<x<<setw(15)<<sin(x)<<setw(15)<<cos(x)<<endl<<endl;
Thank you very much
I just have one more question.

I have to create 3 identical tables

The first one uses a for loop like the one mentioned above. The second and third tables use a while loop and a do while loop respectively. How do I separate the loops from each other. The out put for all three loops is only one table.
Last edited on
just use brackets to close .
1
2
3
4
5
6
7
8
9
10
11
12
13
for (loop)
{
    your code
}

while (loop)
{
    your code
}

do {
    your code
} while(loop);
Last edited on
how do you want to create your table?
Topic archived. No new replies allowed.