Programming Forums
User Name Password Register
 

RSS Feed
FORUM INDEX | TODAY'S POSTS | UNANSWERED THREADS | ADVANCED SEARCH

Reply
 
Thread Tools Display Modes
Old Jan 28th, 2008, 1:08 PM   #1
WalterSlopeboi
Newbie
 
Join Date: Jan 2008
Posts: 9
Rep Power: 0 WalterSlopeboi is on a distinguished road
Program I did for a class today...did I do it correctly?

Instructions:

I. The program asks for the user to input the magnitudes and angles (with respect to X-axis) for two vectors, A and B. It then calculates the resultant vector (R) by summing the X- and Y-components of the two vectors, and prints the magnitudes, and angles (with respect to X-axis) of the vectors A, B, and R on the screen in the format given below.

II. Helpful Math Hints
Rad_A = Deg_A * PI/180

Rx = A cos (rad_A) + B cos(rad_B)
Ry = A sin (rad_A) + B sin(rad_B)

R = √ (Rx^2 + Ry^2), and rad_R = [atan(Ry/Rx)*180/PI]

III. Helpful Programming Hints:

1. Preprocessor define PI = 3.14159
2. Define variables A, B, R, deg_A, rad_A, deg_B, Rad_B, deg_R, rad_R, Rx, Ry as "double/or float"
3. Ask user to enter A in newtons, read the value and assign to A; ask to enter deg_A in degrees, read the value (scan in lf format/or float number as appropriate) and assign to deg_A, and so on...for all the input variables.
4. Computer the rad_A, rad_B, and computer the components (Rx and Ry) of the resultant (R):
5. Computer the resultant vector's magnitude: R = √ (Rx^2 + Ry^2)
6. Compute the resultant vector's directions in degrees:



#include <stdio.h>
#include <math.h>
#define PI 3.14159

int main()
{
double A,B,R,deg_A,rad_A,deg_B,rad_B,deg_R,rad_R,Rx,Ry;

printf("*My name* 2441203 SA33\n");
printf("ESC151 Spring 08\n");
printf("Recitation 1 Jan 28, 2008\n\n\n");


printf("Enter magnitude of A in newtons \n");
scanf("%lf", &A);
printf("Enter direction of A in degrees \n");
scanf("%lf", &deg_A);
printf("Enter magnitude of B in newtons \n");
scanf("%lf", &B);
printf("Enter direction of B in degrees \n");
scanf("%lf", &deg_B);

rad_A=deg_A*PI/180;
rad_B=deg_B*PI/180;
Rx=A*cos(rad_A)+B*cos(rad_B);
Ry=A*sin(rad_A)+B*sin(rad_B);
R=sqrt(Rx*Rx+Ry*Ry);
deg_R=atan(Ry/Rx)*180/PI;

printf("Force(N)				Direction(degrees) \n");
printf("A %lf					%lf\n",A,deg_A);
printf("B %lf					%lf\n",B,deg_B);
printf("R %lf					%lf\n:,R,deg_R);

	return 0;

}
WalterSlopeboi is offline   Reply With Quote
Old Jan 28th, 2008, 1:23 PM   #2
Sane
Programming Guru
 
Sane's Avatar
 
Join Date: Apr 2005
Location: Waterloo, Ontario
Posts: 1,869
Rep Power: 5 Sane will become famous soon enough
Send a message via MSN to Sane
Re: Program I did for a class today...did I do it correctly?

Why don't you tell me?

It looks promising, but you have a typo on your last printf statement. Literals are terminated with a quotation mark. Not a colon.

See what happens when you input:

1
270
1
180

You get an answer in the first quadrant. The answer should be in the third quadrant (225) with magnitude sqrt(2). Do you need to account for this?
Sane is offline   Reply With Quote
Reply

Bookmarks

« Previous Thread in Forum | Next Thread in Forum »

Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
template class brad sue C++ 1 Mar 25th, 2007 5:46 PM
Language display in program Prm753 C++ 3 May 30th, 2006 5:45 PM
Creating a program to test a program sixstringartist C 8 Jan 21st, 2006 1:15 PM
Problem Compiling this program OUfanAP12 Java 4 Nov 7th, 2005 7:27 PM
grading program Rsitapara C++ 8 Feb 27th, 2005 11:42 PM




DaniWeb IT Discussion Community
All times are GMT -5. The time now is 2:37 AM.

Powered by vBulletin® Version 3.7.0, Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Copyright ©2007 DaniWeb® LLC