need help

hello i need help with that program
it have to write the funtion of sin
please help me


/*
** Izena/Nombre :
**
**---------------------------------------------------------------------------------
**
** ENUNTZIATUA
** Programa hau konpilatzean errore eta ohar mezu batzuk agertzen dira.
** Eta gainera, GAIZKI funtzionatzen du exekutatzen denean.
** Aldatu programa hau warning guztiak kentzeko eta ondo funtzionatu dezan.
*/

#include <math.h> // ANSI function prototypes
#include <stdio.h> // Prototype of 'printf' function
#include <stdlib.h> // Prototype of 'system' & 'exit' functions

/************************************************
* 1.- SYMBOL DEFINITIONS *
************************************************/

#define PIx2 6,283 // 2 . PI
#define DELTA 0,300 // Increment step

/************************************************
* 2.- NEW DATA TYPES *
************************************************/

typedef enum {
ERROR = -1,
OK
} Ret_cod_t;

/************************************************
* 3.- FUNCTION PROTOTYPES *
************************************************/

int main (void);
void Print_Stars (int nos);

/***************** main *********
* Shows a sinusoid wave in the screen. *
************************************************/

int main (void)
{
double number_of_stars, angle = 0;

while (angle = PIx2);
{
number_of_stars = 40 + 30 * sin (angle);
Print_Stars ((int) number_of_stars); // print line with stars
angle += DELTA;
}
printf ("\n\n"); // and repeat
system ("Pause"); // Wait for a keystroke
return (OK);
}


/************ Print_Stars *********
* *
* Prints a line of 'nos' asterisks. *
* *
* Input: int nos (number of stars-asterisks *
* Output: nothing *
* *
************************************************/

void Print_Stars (int nos)
{
int i = 0;

while (i < nos)
{
printf ("*");
i++;
}
printf ("\n");
}
Basically, your code needs to generate a vertical sine wave in ascii art?

Please use code tags to make your code more readable.

I do see some mistakes already:

1
2
3
while (angle = PIx2);
{
// etc... 


Do not write a semicolon after the while line, or it'll disconnect the while statement from the block of code that makes up your loop.

(angle = PIx2), note that you're using only one =, so this is an assignment, not a comparison. Use == instead. Also, are you shure you didn't mean a less-than or greater-than comparison? (<, <=, >, >=)

If you correct those, does it work?

Also, your constants use a "," as the decimal seperator. Use a "." instead.

Your program then becomes:
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
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
#include <math.h> // ANSI function prototypes
#include <stdio.h> // Prototype of 'printf' function
#include <stdlib.h> // Prototype of 'system' & 'exit' functions

/************************************************
* 1.- SYMBOL DEFINITIONS *
************************************************/

#define PIx2 6.283 // 2 . PI
#define DELTA 0.300 // Increment step

/************************************************
* 2.- NEW DATA TYPES *
************************************************/

typedef enum {
ERROR = -1,
OK
} Ret_cod_t;

/************************************************
* 3.- FUNCTION PROTOTYPES *
************************************************/

int main (void);
void Print_Stars (int nos);

/***************** main *********
* Shows a sinusoid wave in the screen. *
************************************************/

int main (void)
{
double number_of_stars, angle = 0;

while (angle < PIx2)
{
number_of_stars = 40.f + 30.f * sin (angle);

Print_Stars ((int) number_of_stars); // print line with stars
angle += DELTA;
}

return 0;
}


/************ Print_Stars *********
* *
* Prints a line of 'nos' asterisks. *
* *
* Input: int nos (number of stars-asterisks *
* Output: nothing *
* *
************************************************/

void Print_Stars (int nos)
{
int i = 0;

while (i < nos)
{
printf ("*");
i++;
}
printf ("\n");
}

Last edited on
it works better but it do that
************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************
************************************************************************************************************************************************************************************
it have to do like that
*
**
***
*****
*******
*****
**
**
***
****
******
********
please i need it in a hour
thanks for your help
many thanks, you saved me from failing an exam
Last edited on
You welcome.

The reason it didn't work was because you wrote your constants as "0,300";

I don't know why that compiled (could someone tell me?), but basically it threw away the decimal part, and added 0 to the angle.

Also, the link you posted requires a password to visit.
Last edited on
Topic archived. No new replies allowed.