This is my program so far i don't get the right values =/
Code:
#include <stdio.h>
#include <stdlib.h>
#include <strings.h>
#include <math.h>
//use #define for PI
#define PI 3.14159265359
//Function prototypes
void prob1(void);
void prob2(void);
void ellipse(double a, double b, double x0, double y0, double theta0);
int main(void)
{
int menu;
printf("\nThere are two parts.\n");
printf("Enter the part number to execute (1, or 2): ");
scanf("%d", &menu);
// form a switch to execute one part
switch(menu){
case 1:
prob1();
break;
case 2:
prob2();
break;
default:
printf("part %d does not exist.\n", menu);
}
exit(0);
}
void prob1(void)
{
//Declare a, b, x0, y0, and theta0 here
double a=2.0, b=1.0, x0=2.0, y0=1.0, theta0=30.0;
//Call ellipse here
ellipse( a, b, x0, y0, theta0);
return;
}
void ellipse(double a, double b, double x0, double y0, double theta0)
{
//Add your statement
int n, degree;
double x, y, theta;
printf("#-------------------------------\n");
printf("#theta x-coord y-coord\n");
printf("#-------------------------------\n");
for (n=0; n<=36; n++){
degree = n/.1;
theta = degree*(180/PI);
if(theta==0){
x=x0+a*cos(theta);
y=y0+b*sin(theta);
printf("%4d %12.3e %12.3\n",degree, x, y);
}else{
x = x0 + a*cos(theta)*cos(theta0)-b*sin(theta)*sin(theta0);
y = y0 + a*cos(theta)*sin(theta0)+b*sin(theta)*cos(theta0);
printf(" %4d %12.3e %12.3e\n", degree, x, y);
}}
return;
}
void prob2(void)
{
//Add your statements
FILE *infile;
char text [75];
int count =0;
printf("\n");
infile = fopen("in_ellipse.dat", "r");
if (infile==NULL){
printf("The input file does not exist.\n");
exit(0);
}else
while(fgets(text,75,infile)!=NULL)
{
count++;
printf("%s",text);
}
printf("\n There are %d lines.\n",count);
fclose(infile);
return;
}