it wont loop..

i think im having a problem with the variables...
thank you guys///


Design a program in C whose task is to compute the values of the following two functions of angle θ specified in degrees over two user-specified contiguous angle zones:

F1 = sin θ + 2 cos 2θ for θ1 ≤ θ ≤ θ2, and
F2 = sin 2θ – cos θ for θ2 < θ ≤ θ3

where θ1, θ2 and θ3 are user-specified values of angle θ, with increment in value of θ from one value to the next being Δθ which is also user-specified. When executed, the program will do the following in the indicated sequence:

1. Ask the user to type on the keyboard values of the angles θ1, θ2, θ3, and Δθ.
2. The program will then compute the values of F1 and F2 over the indicated angle zones.
3. The program will then produce a console display in a tabular format of the values of θ (degrees), θ (radians), F1 and F2, with each of the four columns in the display being 16 characters wide, and the four variable values displayed as floating point numbers with two places of decimal which are left-justified in the columns.

Use the following input values for generating your sample output: θ1 = -300, θ2 = 700, θ3 = 1300, and Δθ = 100.


----------------------------------------------------------------------------

#include<stdio.h>
#include<math.h>
#define pi 3.14

int main(){
float theta,theta1,theta2,theta3,increments,i;
float degrees,radians,F1,F2;

printf("enter a value for theta1: ");
scanf("%f",&theta1);
printf("enter a value for theta2: ");
scanf("%f",&theta2);
printf("enter a value for theta3: ");
scanf("%f",&theta3);
printf("enter a value for increments: ");
scanf("%f",&increments);

printf("\n\tANGLE(DEGREES)\tANGLE(RADIANS)\tF1----------\tF2----------\n");
printf("\n\t------------\t------------\t------------\t------------\n");

for(i=theta1;i<=theta3;i=i+increments){
degrees=i;
radians=(degrees*pi)/180;
radians += i;
for(i=theta1;i<=theta2;i=i+increments){
theta=degrees;
F1=(sin (theta))+(2*(cos (2*(theta))));
theta += i;;
for(i=theta2;i<=theta3;i=i+increments){
theta=degrees;
F2=(sin (2*theta))-(cos (theta));
theta += i;

}
}
printf("\n\t%-10.2f\t%-10.2f\t%-10.2f\t%-10.2f\n",degrees,radians,F1,F2);

}

getchar();

return 0;
}


1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
	for(i=theta1;i<=theta3;i=i+increments){ //this loop will end if `i' surpasses `theta3'
		degrees=i;
		radians=(degrees*pi)/180;
		radians += i;
		for(i=theta1;i<=theta2;i=i+increments){
			theta=degrees;
			F1=(sin (theta))+(2*(cos (2*(theta))));
			theta += i;;
			for(i=theta2;i<=theta3;i=i+increments){
				theta=degrees;	
				F2=(sin (2*theta))-(cos (theta));
				theta += i;

			} //i>theta3
		}
		printf("\n\t%-10.2f\t%-10.2f\t%-10.2f\t%-10.2f\n",degrees,radians,F1,F2);

	}
when you reach the output line `i' > `theta3', so the outer loop ends.


1
2
3
4
5
6
7
8
9
//begin=theta1, end=theta2
for(double theta=begin; theta<=end; theta+=delta){
   F1 = sin(theta) + 2*cos(2*theta);
}

//begin=theta2+eps, end=theta3
for(double theta=begin; theta<=end; theta+=delta){
   F2 = sin(2*theta) - cos(theta);
}
Last edited on
THANK YOU SO MUCH FOR HELP !!!
so only thing that i missed was "double"...
BUT why do i need the "double" there??
i really appreciate it if you could spare another minute for me...
thank you again ne555!!! :)
AND what's "eps"?
Last edited on
> so only thing that i missed was "double"...
no.
You've got three nested loop where you use the same variable for the condition. They should be different variables, and the loops shouldn't be nested.

> AND what's "eps"?
Your second condition does not take the beginning θ2 < θ ≤ θ3
you do not start at θ2, but a little later.
yeah you are right!!
thank you again for help , so this below kinda works fine for now...



#include<stdio.h>
#include<math.h>
#define pi 3.14

int main(){
float theta,theta1,theta2,theta3,increments,i;
float degrees,radians,F1,F2;

printf("enter a value for theta1: ");
scanf("%f",&theta1);
printf("enter a value for theta2: ");
scanf("%f",&theta2);
printf("enter a value for theta3: ");
scanf("%f",&theta3);
printf("enter a value for increments: ");
scanf("%f",&increments);

printf("\n\tANGLE(DEGREES)\tANGLE(RADIANS)\tF1 \tF2\n");
printf("\n\t------------\t------------\t------------\t------------\n");

for(i=theta1;i<=theta3;i=i+increments){
degrees=i;
radians=(degrees*pi)/180;
radians += i;
if(i>=theta1 && i<=theta2){
for(double i=theta1;i<=theta2;i=i+increments){
theta=degrees;
F1=(sin (theta))+(2*(cos (2*(theta))));
theta += i;
if(i==theta2){
break;
}
}
printf("\n\t%-10.2f\t%-10.2f\t%-10.2f\n",degrees,radians,F1);
}
else {
for(double i=theta2;i<=theta3;i=i+increments){
theta=degrees;
F2=(sin (2*theta))-(cos (theta));
theta += i;
if(i==theta3){
break;
}

}
printf("\n\t%-10.2f\t%-10.2f\t\t\t%-10.2f\n",degrees,radians,F2);
}



}

getchar();

return 0;
}



Topic archived. No new replies allowed.