C Program  | | |
March 13th, 2007, 03:35 PM
|
#1 (permalink)
| | Junior Member
Join Date: Mar 2007
Posts: 3
|
Well I know I am a newbie to this forum, so sorry if I am posting in the wrong spot, I spent a little bit trying to look for the C part of this Forum, but couldn't find one (guess I am either blind or lazy). Well I need some help I have a program started but can't seem to finish it. This is the program requirements:
Cross-sectional area: base * height
Moment of inertia: (base * height3) / 12
Section Modulus: (base * height2) / 6
The company makes lumber with base sizes of 2, 4, 6, 8, 10 inches. The height sizes are
2, 4, 6, 8, 10, 12 inches. All combinations are possible. Produce a table as below showing
the computed engineering properties, using proper formatting. (Use for/while/do-while
loops, whatever suits you.) Use flow charts to first describe the basic problem solution
(details of formatting can be omitted).
Input data for the algorithm: Base and Height (predefined – no input from user)
Output: A table as shown below. (Only partial table shown – compute the entire table)
Lumber Size Cross-sectional Moment of Section
Base * Height Area Inertia Modulus
---------------- ------------------ ---------------- ----------------
2 * 2
2 * 4
2 * 6
2 * 8
2 * 10
2 * 12
4 * 2
4 * 4
4 * 6
4 * 8
4 * 10
4 * 12
6 * 2
6 * 4
6 * 6
.
.
Here is the program I have right now:
#include<stdio.h>
int main ()
{
printf("Lumber Size"; "Cross-Sectional Area"; Moment of Inertia"; "Section Modulus");
for (counter=2; counter<=12; counter++2)
printf("%d"; "%3d"; "%10.2f"; "%10.2f", counter);
return 0;
}
So any help ASAP would be great. I probably will have more programs I'll need help with so I'll just keep posting them in this thread. Thanks anyone, this will help me a lot. I am a beginner in programing by the way. |
| |
March 13th, 2007, 03:45 PM
|
#2 (permalink)
| | Anime Otaku
Join Date: Oct 2001 Location: Tampa, FL USA
Posts: 108,975
|
Welcome to TechIMO.  I have moved your thread to the programming forum for better community visibility.
__________________ Robert Richmond | TechIMO Community Relations Director
Infinite perceptions. One reality. FanFiction.Net - Unleash your imagination. |
| |
March 13th, 2007, 03:46 PM
|
#3 (permalink)
| | Junior Member
Join Date: Mar 2007
Posts: 3
|
Ok thanks, yeah sorry, didn't know about section. |
| |
March 13th, 2007, 03:49 PM
|
#4 (permalink)
| | Senior Member
Join Date: May 2003 Location: Aus, Gold Coast :)
Posts: 802
|
try webmastering and programming forum - as far as you are concerned you might have to pay me to give you the answer if u are going to continue to put programs up... but i will give you a hint - you a close, but Start at the greatest piece of lumber, and keep filling the space until u are down to 2 inches and then there is no space left :P
(on the assumption that you have a Space to be field using the greatest piece of lumber first)
also a bit more information would be nice
also after re-reading you thread again and again you can basically ignore what i have said above -
so i can understand u need to;
User Inputs Values - base and height
Using those values u have to find the Inertia, etc etc using those calculations?
Last edited by exally : March 13th, 2007 at 03:57 PM.
|
| |
March 13th, 2007, 03:55 PM
|
#5 (permalink)
| | Senior Member
Join Date: May 2003 Location: Aus, Gold Coast :)
Posts: 802
|
you will need a nested for loop within your current for loop of basically the same style - move all calculations and output into that nested loop.
then use something like ((double)counter*(double)counter2) / 12 - to calc inertia
all i am doing there is typecasting the counter to a double so when you do the calculations you will recieve a double back (which u can they convert to float) then print that to the screen |
| |
March 13th, 2007, 04:30 PM
|
#6 (permalink)
| | Super F@D Folder
Join Date: Jun 2004
Posts: 5,083
|
you'll need 2 loops....the outer loop iterates though your base sizes.....the inner loop to iterate through your height sizes. give that a shot and if you can't get it from there maybe we'll help more (we don't really like doing homework though...you ought to try and figure it out yourself and come to us if you REALLY can't figure it out with MUCH more specific questions). |
| |
March 13th, 2007, 04:33 PM
|
#7 (permalink)
| | Junior Member
Join Date: Mar 2007
Posts: 3
|
Well thank you. I thought I needed 2 "for" statements, but really wasn't sure. I like do ... while loops, and detest "for" even if they are smaller. I have asked the prof for help, and she helped me a bit, but I am still having trouble. I think I got it now though, thanks all! |
| |
March 13th, 2007, 04:42 PM
|
#8 (permalink)
| | Super F@D Folder
Join Date: Jun 2004
Posts: 5,083
|
learn to love for loops...they really do have their place...i use them more than any other loops! |
| |
March 13th, 2007, 05:00 PM
|
#9 (permalink)
| | Senior Member
Join Date: May 2003 Location: Aus, Gold Coast :)
Posts: 802
|
while loops are theoretically quicker sr7100 - and better too if u have multiple escape clauses but it all depends in the situation, navigating an array or something similar definately use for loops also do-while loops i very rarely see
though the best loop to learn to do is the function recursion, they are just plain sadistic |
| |
March 13th, 2007, 06:01 PM
|
#10 (permalink)
| | Super F@D Folder
Join Date: Jun 2004
Posts: 5,083
|
I'm thoroughly in love with recursion. I had it stuffed down my throat last semester and now that i understand it....life is SOOO much easier when it comes to programming. You still attempt to use iteration when possible for the sake of resources but if it's a small problem then recursion is amazing. The trick is learning to turn it into tail recursion if possible...save yourself a CRAPLOAD of resources that way as the problem gets large!!! |
| | | Thread Tools | Search this Thread | | | |
Similar Threads | | Thread | Thread Starter | Forum | Replies | Last Post | | Is this program ok? | cpembo | Security and Privacy Issues | 6 | September 11th, 2005 05:17 PM | | Need Program! | eminem_rh25 | General Tech Discussion | 1 | July 1st, 2005 06:10 PM | | looking for a program... | jpiermarini | General Tech Discussion | 7 | April 25th, 2005 04:27 PM | | C Program | magicz69 | General Tech Discussion | 1 | July 12th, 2004 01:12 PM | | i Need program... | nice moon | General Tech Discussion | 2 | June 16th, 2002 07:53 PM | |
Currently Active Users Viewing This Thread: 1 (0 members and 1 guests) | | | | Most Active Discussions | | | | | Recent Discussions  | | | | | |