I need to create a program that displays the graph of an increasing frequency sine wave. The program should ask the user for an initial step size in degrees and the number of lines of the graph to display. I thought I had the program done but when I run it and enter anything as the initial step size and 10 lines to print I see something like this: (no matter what number in degrees I print)
*
*
*
*
*
*
*
*
*
*
Here is my code: (can someone tell me what is wrong?)
#include <stdio.h>
#include <math.h> /* contains sin function */
#define PI 3.14 /* used in conversion of degrees to radians */
#define SCALE 35
void main(void)
{
int counter, index, lines;
double degree, radians, scale_sine;
printf("Type in the initial step size in degrees:\n");
scanf("%lf", °ree);
printf("Type in the number of lines to be printed:\n");
scanf("%d", &lines);
radians = degree * PI/180; /* convert degrees to radians */
scale_sine = SCALE * sin(radians);
for(counter = 0; /* loop to print sine wave */
counter < lines;
++counter)
{
for(index = -SCALE;
index < scale_sine;
++index)
{
printf(" ");
}
printf("*\n");
}
}



LinkBack URL
About LinkBacks



