I'm doing a C program that involves printing out a sine wave using the "*" character. The main coding is complete but for some strange reason the "*"'s just won't display on the screen. All I'm getting is blanks. Here's my code:
#include <stdio.h>
#include <math.h>
int main(void)
{
/* Declare variables */
int line_count, /* Counts the lines in the program */
no_of_lines; /* The number of lines to display in the graph */
double result, /* The sine result from the calculation */
initial_step_size, /* The initial step size in degrees */
current_step_size, /* The current step size in degrees */
sine_count; /* Counts the values in the sine range */
/* Prompt user for information */
printf("\nEnter the initial step-size in degrees: ");
scanf("%lf", &initial_step_size);
printf("\nEnter the number of lines to be displayed in the graph: ");
scanf("%d", &no_of_lines);
/* Assign to current step size */
current_step_size = initial_step_size;
/* Display graph */
for (line_count = 0; line_count < no_of_lines; line_count++)
{
result = sin(current_step_size);
for (sine_count = -1; sine_count <= 1; sine_count += 0.01)
{
if (result == sine_count)
printf("\n*\n");
else
printf(" ");
}
/* Increment step size */
current_step_size += initial_step_size;
}
return 0;
}
Both for loops run well and displayed the necessary values during tests. The only problem left is the if condition that is supposed to compare the calculated sin result with the sine range value. Basically, if the result matches the sine range value, display a star. Otherwise, display a blank. Is it a problem with my code? Or is it possible that it may be a problem with my compiler?Any help will be appreciated. Thanks! :)


Sign In
Create Account


Back to top









