C++

Hi,

Can anyone help with this with the error I am getting?

#include <iostream>
#include <cmath>
#define PI 3.1416


using namespace std;

int main()

//Q1-------------------------------------------------------------------------------------------
{
for (theta=0;theta<=21;0<theta<=2PI)

double theta;
double sin<theta>;
double cos<theta>;
double tan<theta>;




cout << ""<<sin << endl;
return 0;
}
I think you dont quite get the feel of it.
(1)double theta needs to be declared first before or in for iteration

(2) 0<theta<=2PI is a bad expression. Use
0<theta && theta<=2PI

(3)Paramenter bound uses "()" not "<>"

(4) your for loop will only loop the next statement if you do not use "{}" to wrap around;
Last edited on
Can you explain what you are trying to do Charle?

Also sin/cos/tan are functions so you can't name variables that or it will more than likely have naming conflicts. Also even if you did declare theta before the for loop it would be an endless loop because you never increment it.


Once again if we had a formula or what exactly you are trying to do we could be of more help.
Giblit,

I am attempting write a program that uses a for loop to compute and output Sin(0), Cos(0), Tan(0) for 21 values of 0(theta) equally spaced between 0 and 2Pi.
so In other words you are going from 0 -> 6.28318 over 21 iterations. So basically the for loop would look like:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
double theta;
const double max = 6.28318; //estimate of 2pi
const int iterations = 20; //we must iterate 20 times
                           // after the initial 0 for a total of 21
const double threshold = 0.0000001; //threshold for comparing doubles

for( theta = 0.0; theta < max + threshold; theta += max / iterations )
{
    std::cout << "Cos(" << theta << ") = " << cos( theta ) << std::endl;
    //repeat for sin and tan.
}
Cos(0) = 1
Cos(0.314159) = 0.951057
Cos(0.628318) = 0.809017
Cos(0.942477) = 0.587786
Cos(1.25664) = 0.309018
Cos(1.57079) = 1.32679e-06
Cos(1.88495) = -0.309015
Cos(2.19911) = -0.587784
Cos(2.51327) = -0.809016
Cos(2.82743) = -0.951056
Cos(3.14159) = -1
Cos(3.45575) = -0.951057
Cos(3.76991) = -0.809019
Cos(4.08407) = -0.587788
Cos(4.39823) = -0.309021
Cos(4.71239) = -3.98038e-06
Cos(5.02654) = 0.309013
Cos(5.3407) = 0.587782
Cos(5.65486) = 0.809014
Cos(5.96902) = 0.951055
Cos(6.28318) = 1


http://ideone.com/4g8JHu
theta sin(theta) cos(theta) tan(theta)
----------------------------------------------------------------------
0.000000 0,000000 1.0000000 0.00000000
0.314







how would you setup a list that end @ 20 values
Just modify the output on the last message I said to your format.
Topic archived. No new replies allowed.