well, im fiddling around with the code and i think im almost there, i just need to make it so that when it writes to a .txt file, it prints out an X and Y lines along with STARS that resemeble the SIN(x) graph, just the top portion, but all i get are just plain stars all the same lengths....this is what the program is supposed to do, print to a .txt file this:
_________y
|*
|**
|***
|****
|***
|**
|*
x
except supposed to be around as long as the Y graph....how do i calculate it into this code???This program should graph the funcion y=sin(x)
on the interval from 0 to pi in incriments of pi/20.
Code:
#include <stdio.h>
#include <stdlib.h>
#include <math.h>
main()
{
const float pi=3.1459;
float x, /*values for x in radians*/
y; /*outputted number of stars*/
int stars,
i =0.0; /*number of stars graphed*/
FILE*fptr=NULL;
if((fptr =fopen("c:outputfilename.txt","w")) ==NULL) /*test if files opened correctly*/
printf("\nError opening file\n\n");
else
{
for(i=1; i<=60; ++i) /*for loop to print the y axis*/
fprintf(fptr,"_");
fprintf(fptr," Y\n");
for(x=0; x<=20.0; ++x) /*for loop to calculate the function*/
{ /*values and the number of stars*/
int g;
g=sin(x*pi+1);
fprintf(fptr,"|"); /*prints the x-axis*/
for(y=g ;y<=20.0;++y) /*for loop to print the stars*/
fprintf(fptr,"*");
fprintf(fptr,"\n"); /*go to new line after printing a row*/
} /*of stars*/
fprintf(fptr,"|\n|\nX");
fclose(fptr);
}
system("pause");
return 0;
}