MY QUESTION IS BASED ON A COURSEWORK

I am trying to produce a sin wave using *'s to represent sample values for 1 cycle of the wave. For example when the user enters 7 the output should look like this:

``````.........................................................*
..........................................................................*
..........................................................................*
.........................................................*
.......................................*
.......................................*
.........................................................*
``````

please ignore the "......" its the only way i can get the `*`'s to stay where they are
My attempts

To try and get a load of values that can be 'plotted' as `*`'s, i have used a counter to count 0 upto the value the user has entered. leaving me with for this example 1 -> 7 (values to help me split up the sine wave) These values are placed into an array `a[x]`. Next i have said `a[10]=360/a[x]` producing equal degree values, 60, 120, 180, 240, 300, 360. Then i have to either convert them to radians before take the sin of them or leave them in degrees(but as this is courswork i need to figure that bit out!)

``````int a[30];           //array called a which has 100 integers
int b[10000];
int x;

for ( x=1; x<=rate-1; x++ ) {  //does counting x=1 -> x=rate-1
a[x] = x;

b[0] = (360 / a[x]);

cout << b[0] << endl;}
``````

note counter starts at one to avoid 360 / 0*

At the moment my program works in terms of prompting the user to enter a value such as 7 and then working out the degrees for 1 cycle (360).

My problem lies with taking the sin of the values within b[0] which forever produces an overload error. Is there an easier way of showing the degree values for one cycle. I have literally gone through every possibilie i can think off. For example:

``````if ( rate = 7 ) {
int a [7] = { 0, 90, 120, 180, 240, 300, 360 } }

***** AND ALSO ******

for ( x=1; x<=rate-1; x++ ){
a[1] = x;
a[2] = 360 / x;
cout << a[2] <<  endl;}
a[3] = sin(a[2]);
b[a2] = a[2]; }

****************
``````

For all the coding above i am trying to acheive the sine of each of the degree angles so i can put them in the formula below:

``````* output position = centrepoint + scalefactor * sin(radian angle)
``````

Can anyone provide me with any tips on how they would calculate and store the degree values so i can use a sin function on them. Something easier than how im going about doing it?

I know this post is confusing but i will explain it again if need be.

## All 8 Replies

>a[10]=360/a[x]

Didn't understand why.

>int a[[B][U]30[/U][/B]]; //array called a which has 100 integers

How 100?

You are approaching the problem in a very roundabout manner. Try something like this.

``````double no,a[10]; // Try using dynamic memory allocation here.
int i;
// Let the user input value of no here.
no=360/no; // equal spacing between each array element.
for(i=1;i<=no;i++)
{
a[i]=sin(PI*i*no/180);
}
// Display a[i] here.``````

The 100 integer came from a previous attempt where i had set a[100] and commented //a has 100 integers. Later i decided to edit the number of elements but didnt adjust the comment beside.

John

By the way, you should have posted this in the C forum. There is nothing specific to C++ in this thread.

By the way, you should have posted this in the C forum. There is nothing specific to C++ in this thread.

No, the C++ forum is appropriate; he is using C++, not C. If he posted in the C forum people would be wondering why 'cout' is in his code.

right. but he does not need to use cout in order to manipulate pointers. though, what you said is very much right.

commented: nope -2

right. but he does not need to use cout in order to manipulate pointers. though, what you said is very much right.

Erm, I think he is using `*` to represent asterisks not pointers. The '*' is an arbitary character used for displaying the sin wave...

I should have written

right. but he does not need to use cout in order to manipulate arrays. though, what you said is very much right.

then. Okay?

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.