Need to draw a triangle and sine curve

/*this is what i have so far. i already have the triangle part completed sine
curve is giving me problems. not sure where to start. i know i need a for loop from 0 to 180 in increments of 4, then convert that to radians. and call the function *back into main. dont worry about little errors i have just need help with general the placement of parts of void functions */

#include <iostream>
#include <string>
#include <math.h>

using namespace std;
void drawLine (int Length, char displayChar);
void placePoint (int lineLength);

int main()
{
int lineLength=0;
char displayChar;
double radValue = 0.0;
while (true)
{
cout <<"This program draws triangles and sine curves"<<endl;
cout << "********************************" << endl;
cout <<"To draw a triangle press 1." <<endl;
cout << "To draw a sin curve press 2."<<endl;
cout <<"Select 0 to end program" <<endl;
cout <<"Enter a selection please: " <<endl;
cout << "********************************" << endl;

int userSelection=0;
cin >> userSelection;

if (userSelection ==2) ;
{
for (int t=0; t<180; t=t+4);
}
}} //end main

void placePoint (int lineLength)
{
for (int x=0; x< 180; x=x+4)
(x*3.141/180);
{
cout<<" ";
}
cout<< "*"<< endl;
}}
Use the code tags to make your code easier for others to read.
how do you want a sine cure to be displayed?

like this?:
1
2
3
4
5
6
      *                    *
   *    *              *
 *        *          *
*          *        *
             *     *
                *    


ofcourse is this a bit choppy;)
Last edited on
I know i'm not really supposed to give aswers but i couldn't help myself;)

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
#include <iostream>
#include <string>
#include <math.h>
#include <windows.h>

using namespace std; 

/* set cursor macro */
#define setCursor(crd)	SetConsoleCursorPosition ( GetStdHandle ( STD_OUTPUT_HANDLE ), crd )

/* settings */
#define SINEHEIGHT  20
#define DEGREESTEP  5

/* local functions */
void DrawSine (int degree); 

/* main */
int main()
{	
	system("CLS");
	DrawSine(360);
	system("pause");
	return 0;
}

/* draw a sine */
void DrawSine (int degree)
{
	COORD curPos = {0,0};

	for (int x = 0 ; x < degree ; x = x + DEGREESTEP )
	{		
		curPos.X = floor( ( x / DEGREESTEP ) + 0.5 );
		curPos.Y = floor( ( ( ( ( -1 * sin(x * 3.141 / 180 ) ) + 1) * ( SINEHEIGHT / 2 ) ) ) + 0.5 );
		
		setCursor( curPos );

		cout << "*" ;
	}

	curPos.X = 0;
	curPos.Y = SINEHEIGHT+1 ;
	setCursor(curPos);
}


               *******
            ***       ***
          **             **
         *                 *
       **                   **
      *                       *
     *                         *
   **                           **
  *                               *
 *                                 *
*                                   *
                                     *                                 *
                                      *                               *
                                       **                           **
                                         *                         *
                                          *                       *
                                           **                   **
                                             *                 *
                                              **             **
                                                ***       ***
                                                   *******
Last edited on
thank you.
you over did it actually. i only needed it to go to 180 (forgot to mention that) and i have to have it orientated the other way so it looks like this
*
--*
----*
------*
----*
--*
*
i can figure that out though
thanks for your help
Last edited on
i did not really help... i just gave an answer...;) and you can enter 180 instead of 360 in main.
Last edited on
Topic archived. No new replies allowed.