Question
I want to do a while loop for would you like to perform another code. Plase help me fix my programs. My code is not
I want to do a while loop for would you like to perform another code. Plase help me fix my programs. My code is not working, I am so confused.
double Magn(double V[]) { double m; m = sqrt(V[0] * V[0] + V[1] * V[1] + V[2] * V[2]); return m; }
double Dotp(double V1[], double V2[]) { double dotp; dotp = V1[0] * V2[0] + V1[1] * V2[1] + V1[2] * V2[2]; return dotp; }
double Ang(double dotp, double m1, double m2) { double angle; angle = acos(dotp / (m1 * m2)) * 180 / 3.1415926; return angle; }
void CrossP(double V1[], double V2[], double crossp[]) { crossp[0] = V1[1] * V2[2] - V1[2] * V2[1]; crossp[1] = -V1[0] * V2[2] + V1[2] * V2[0]; crossp[2] = V1[0] * V2[1] - V1[1] * V2[0];
}
int main(void) { double V1[3]; double V2[3]; double m1; double m2; double dotp; double crossp[3]; double angle; char flag = 'a'; char YN = 'y'; int i;
while (YN=="y") { printf("Enter M to calculate the magnitude of a single 3-D vector "); printf("Enter D to calculate the dot product of two 3-D vectors "); printf("Enter C to calculate the cross product of two 3-D vectors "); scanf("%c", &flag);
if (flag == 'M') { printf("Enter in Vx Vy Vz (separated by spaces) ");
for (i = 0; i | = %lf ", V1[0], V1[1], V1[2], m1); }
if (flag == 'D') { printf("Calculating the dot product between V1 and V2 "); printf("Enter in Vx1 Vy1 Vz1 (separated by spaces) "); for (i = 0; i
printf("V1 dot V2 = %lf, theta = %lf degrees", dotp, angle); }
if (flag == 'C') { printf("Calculating the dot product between V1 and V2 "); printf("Enter in Vx1 Vy1 Vz1 (separated by spaces) "); for (i = 0; i , theta = %lf degrees", crossp[0], crossp[1], crossp[2], angle); }
printf("Would you like to perform another calculation? (y)"); scanf("%c", &YN);
} return 0;
}
Sample Code Execution: Red text indicatesi Enter M to calculate the magnitude of a single 3-D vector Enter D to calculate the dot product of two 3-D vectors Enter C to calculate the cross product of two 3-D vectors Enter in Vx Vy Vz (separated by spaces) 1 2 3 Ivi = !| 3.74165739 Would you like to perform another calculation? (y)j Enter a valid input Would you like to perform another calculation? (y)y Enter M to calculate the magnitude of a single 3-D vector Enter D to calculate the dot product of two 3-D vectors Enter C to calculate the cross product of two 3-D vectors Enter a valid choice Enter M to calculate the magnitude of a single 3-D vectorStep by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started