# please help me

This is a discussion on please help me within the C Programming forums, part of the General Programming Boards category; Before High resolution graphic displays became common, computer terminals were often used to display graphs of equations using only text ...

1. ## please help me

Before High resolution graphic displays became common, computer terminals were often used to display graphs of equations using only text characters. A typical
technique was to create a vertical graph by spacing over on the screen, then displaying an *. Write a program that displays the graph of an increasing frequency sine wave this way. The program should ask the user for an initial step-size in degrees and the number of lines of the graph to display.

that was my assignment, and i'm almost done, but i got serveral error messages and i don't know how to fix my program, please help me

/* This program wlil graph an increasing frequency sine wave */

#include <stdio.h> /* printf, scanf definitions */
#include <math.h> /* math definitions */
#define pi 3.14159

int
main(void)
{
double stepsize; /* input - stepsize */
double first_value; /* input - first value */
double number_of_lines; /* input - number of lines */
double output;
double loop;
double scale;
double increment;
double y;
double sin;

/* Get the step size, first value, and number of lines */
printf("Enter the inial step size> ");
scanf("%d", &stepsize);
printf("Enter the first value> ");
scanf("%d", &first_value);
printf("Enter the number of lines> ");
scanf("%d", &number_of_lines);

for (int i = 0; i<number_of_lines; ++i)
{
double y = sin(exp(first__value + i * stepsize * 2 * pi / 180));
y *= 10.0; /* Scaling */
y += 5.0; /* Scaling */

/* Output y spaces by using loop */
for (int j = 0; j < y; ++j)
{
printf(" ");
}
printf("*\n"); /* Output '*' and new line) */
}
return 0;
}

2. << !! Posting Code? Read this First !! >>
How big does << !! Posting Code? Read this First !! >> have to be before you read it?
Now click the nice "edit" button at the bottom of your post and try again.

> but i got serveral error messages
Well keeping them a secret won't help - post them

3. typo with this variable
Code:
`double y = sin(exp(first__value + i * stepsize * 2 * pi / 180));`
look at what you are passing to sin()
Code:
`double y = sin(exp(first_value + i * stepsize * 2 * pi / 180));`

4. Code:
```/* This program wlil graph an increasing frequency sine wave */

#include <stdio.h>                      /* printf, scanf definitions */
#include <math.h>                       /* math definitions          */
#define pi 3.14159

int
main(void)
{
double stepsize;                /* input - stepsize     */
double first_value;             /* input - first value  */
double number_of_lines;         /* input - number of lines */
double output;
double loop;
double scale;
double increment;
double y;
double sin;

/* Get the step size, first value,  and number of lines */
printf("Enter the inial step size> ");
scanf("%d", &stepsize);
printf("Enter the first value> ");
scanf("%d", &first_value);
printf("Enter the number of lines> ");
scanf("%d", &number_of_lines);

for (int i = 0; i<number_of_lines; ++i)
{
double y = sin(exp(first_value + i * stepsize * 2 * pi / 180));
y *= 10.0; /* Scaling */
y += 5.0;  /* Scaling */

/* Output y spaces by using loop */
for (int j = 0; j < y; ++j)
{
printf(" ");
}
printf("*\n"); /* Output '*' and new line) */
}
return 0;
}```
code tags added by Kermi3

i'm still getting these error messages...

sine.c: In function `main':
sine.c:28: error: `for' loop initial declaration used outside C99 mode
sine.c:30: error: called object is not a function
sine.c:35: error: `for' loop initial declaration used outside C99 mode[SIZE=5]

5. Code:
```/* This program wlil graph an increasing frequency sine wave */

#include <stdio.h>                      /* printf, scanf definitions */
#include <math.h>                       /* math definitions          */
#define pi 3.14159

int
main(void)
{
double stepsize;                /* input - stepsize     */
double first_value;             /* input - first value  */
double number_of_lines;         /* input - number of lines */
double output;
double loop;
double scale;
double increment;
double y;
double sin;

/* Get the step size, first value,  and number of lines */
printf("Enter the inial step size> ");
scanf("%d", &stepsize);
printf("Enter the first value> ");
scanf("%d", &first_value);
printf("Enter the number of lines> ");
scanf("%d", &number_of_lines);

for (int i = 0; i<number_of_lines; ++i)
{
double y = sin(exp(first__value + i * stepsize * 2 * pi / 180));
y *= 10.0; /* Scaling */
y += 5.0;  /* Scaling */

/* Output y spaces by using loop */
for (int j = 0; j < y; ++j)
{
printf(" ");
}
printf("*\n"); /* Output '*' and new line) */
}
return 0;
}```
I havent changed a thing. just used the code thingy to make it look nicer for others

6. Can you not read the huge bold letters from salem well just in case let me do it agian
<< !! Posting Code? Read this First !! >>
<< !! Posting Code? Read this First !! >>
<< !! Posting Code? Read this First !! >>
<< !! Posting Code? Read this First !! >>
<< !! Posting Code? Read this First !! >>
<< !! Posting Code? Read this First !! >>
Heres the nice link for that little post

<< !! Posting Code? Read this First !! >>

for crying out loud read it

7. oh...i didn't know what salem was talking about...thanks...please help me with my errors

8. Originally Posted by my_username1234
i'm still getting these error messages...
and just a *few* others I bet..

Ok, first - declaring a variable inside a for loop is ok in C99, but not outside.

Second, are you trying to call sin()? Then you need to get rid of the variable sin

Code:
`double sin;`

9. Code:
```/* This program wlil graph an increasing frequency sine wave */

#include <stdio.h>                      /* printf, scanf definitions */
#include <math.h>                       /* math definitions          */
#define pi 3.14159

int
main(void)
{
double stepsize;                /* input - stepsize     */
double first_value;             /* input - first value  */
double number_of_lines;         /* input - number of lines */
double output;
double loop;
double scale;
double increment;
double y;
double sin;

/* Get the step size, first value,  and number of lines */
printf("Enter the inial step size> ");
scanf("%d", &stepsize);
printf("Enter the first value> ");
scanf("%d", &first_value);
printf("Enter the number of lines> ");
scanf("%d", &number_of_lines);

for (int i = 0; i<number_of_lines; ++i)
{
double y = sin;
(exp(first_value + i * stepsize * 2 * pi / 180));
y *= 10.0; /* Scaling */
y += 5.0;  /* Scaling */

/* Output y spaces by using loop */
for (int j = 0; j < y; ++j)
{
printf(" ");
}
printf("*\n"); /* Output '*' and new line) */
}
return 0;
}```
and these are the only errors i have left, please help me fix it...i don't know how

sine.c:28: error: `for' loop initial declaration used outside C99 mode
sine.c:36: error: `for' loop initial declaration used outside C99 mode

10. > for (int i = 0; i<number_of_lines; ++i)
Like the message says - this isn't legal syntax for your C89 compiler.

int i; // at the start of the block

for (i = 0; i<number_of_lines; ++i) // like this

11. I am assuming you are not the author of this code...

As I referred to before, you have lines like this:
Code:
`for (int j = 0; j < y; ++j)`
Notice that the variable j is being declared inside the loop. This is ok for the C99 standard, but not in C89. Either declare it outside, with all of your other variables, or use the -std=c99 flag when you compile (if you are using gcc). I think the preference would be the former choice.

edit - curses, foiled again!
~/

12. ahhh! the program is supposed to draw an increasing frequency sine function, but all i get is "*"

Code:
```/* This program wlil graph an increasing frequency sine wave */

#include <stdio.h>                      /* printf, scanf definitions */
#include <math.h>                       /* math definitions          */
#define pi 3.14159

int
main(void)
{
double stepsize;                /* input - stepsize     */
double first_value;             /* input - first value  */
double number_of_lines;         /* input - number of lines */
double output;
double loop;
double scale;
double increment;
double y;
double sin;
double i;
double j;
/* Get the step size, first value,  and number of lines */
printf("Enter the inial step size> ");
scanf("%d", &stepsize);
printf("Enter the first value> ");
scanf("%d", &first_value);
printf("Enter the number of lines> ");
scanf("%d", &number_of_lines);

for (i=0; i<number_of_lines; ++i) //
{
double y = sin;
(exp(first_value + i * stepsize * 2 * pi / 180));
y *= 10.0; /* Scaling */
y += 5.0;  /* Scaling */

/* Output y spaces by using loop */
for (j=0; j < y; ++j) //
{
printf(" ");
}
printf("*\n"); /* Output '*' and new line) */
}
return 0;
}```

13. Why doesn't anyone ever listen to their compiler?
m1234.c: In function `main':
m1234.c:21: warning: int format, double arg (arg 2)
m1234.c:23: warning: int format, double arg (arg 2)
m1234.c:25: warning: int format, double arg (arg 2)
m1234.c:11: warning: unused variable `output'
m1234.c:12: warning: unused variable `loop'
m1234.c:13: warning: unused variable `scale'
m1234.c:14: warning: unused variable `increment'
m1234.c:15: warning: unused variable `y'
Where do you ever assign sin a value?
Why do you have a variable named sin when the math library comes with a function named sin?
What exactly is this supposed to do?
Code:
`(exp(first_value + i * stepsize * 2 * pi / 180));`
Quzah.

14. my compiler doesn't say any of those errors

15. Originally Posted by my_username1234
my compiler doesn't say any of those errors
try "gcc -Wall -ansi filename.c"
to display all warnings

EDIT: i.e if you are using UNIX

Page 1 of 2 12 Last
Popular pages Recent additions