Author Topic: The programming help thread!  (Read 2179 times)

Dark Fact

  • Hero Member
  • *****
  • Posts: 1147
The programming help thread!
« on: May 31, 2007, 06:46:04 PM »
I've decided to start up this here thread in regards to programming, software design, the whole shibang.

Recently, I decided to dust off my old C programming textbook and get the old programming skills running again.  Now, for the record, I've completed my courses at my university and I'm getting my degree next week.  However, my programming skills have been dropping the past couple years and I want to get back on track when it comes time to get a good job in my programming profession.  That said, I've recently decided to go back to university for one more year to take a few extra credit courses in order to fulfill the requirements for a 4 year bachelors in Business Computing (the degree I'm getting next week is a 3 year bachelors in Business Computing).  Since I've already completed all my computing courses, all I can take is a couple of history and literature ones for the time being until I've got all my credits for a 4 year degree.  My goal is to have my programming skills sharpened by next spring so I can be ready to tackle the work force full time.

That said, I'm going to run into a few problems with my programs every now and then such as a function that just won't work for some reason, a stubborn loop, or incorrect data.  That's where I will ask you guys for advice.  If you can point out some things wrong in my programs, I would like to hear it.  Now, for the record, I don't expect anyone here to write the programs for me.  That is supposed to be my job and I need the experience.  All I'm saying is that if I come to a major snag that is beyond my comprehension, I would like a little help. :)

Finishing university is one thing, but getting a major job in my profession is a whole different ball game.  If I'm gonna go into the work force, I wanna go prepared.

So, with that said, let's get down to business.  I have a little program that I was working on in C today that is none other than the familiar "Fahrenheit to Celsius" conversion.  Now, for the record, the program works.  The problem I have with it is that I'm not sure if the output is correct.  The output seems correct but there was a stipulation in the textbook question saying that the celsius values need to be rounded to the nearest integer.  Oh, and by the way, the values have to be displayed as integers.  Here is the output:

CELSIUS     FAHRENHEIT
-----------------------
     -6             20
     -3             25
     -1             30
      1             35
      4             40
      7             45
     10            50
     12            55
     15            60
     18            65
     21            70
     23            75
     26            80
     29            85
     32            90
     35            95
     37           100

The Fahrenheit values are correct as the question asked me to record the values in five degree intervals.  It is the Celsius values that worry me.  For the hell of it, I converted my "int" values into "float" to test to see if they were more accurate and sure enough, they were.  It's just these integer values that leave me inconclusive.  This is why I need a second opinion on the matter.  Are these Celsius values accurate as an integer definition or are a few of the values not rounded properly?

I'm heading to bed now so I won't be back till tomorrow morning to check what you guys have said.  Any help is appreciated! Thanks. :)

Sorry, but I don't see your library card on the books of Ys.  Now, RETURN THEM TO ME!!!

Hobo Xiphas

  • Hero Member
  • *****
  • Posts: 529
Re: The programming help thread!
« Reply #1 on: May 31, 2007, 07:00:09 PM »
You have to use float\double for the variables or else you will get incorrect values since the conversion uses division and it will truncate if you throw it into an int.

Use the truncf\trunc function to round off floats\doubles to the nearest integer respectively after you have done the conversion.

EDIT: I checked the libc man and the above won't work, you'll probably have to use an if structure with floor and ceil of some sort to get it working unless my horrible knowledge of C is making me forget a function in math.h.
« Last Edit: May 31, 2007, 07:05:20 PM by Xiphas »

Keranu

  • Hero Member
  • *****
  • Posts: 9054
Re: The programming help thread!
« Reply #2 on: May 31, 2007, 07:12:16 PM »
This thread is screaming nodtveidt.
Quote from: Bonknuts
Adding PCE console specific layer on top of that, makes for an interesting challenge (no, not a reference to Ys II).

offsidewing

  • Hero Member
  • *****
  • Posts: 631
Re: The programming help thread!
« Reply #3 on: June 01, 2007, 02:50:50 AM »
Sheeee-it.  I got some programming knowledge for you.

Gorillas on Qbasic is the bomb.  Nibbler, not so much.

Oh how the Radioshack at the mall hated me C:\format bitches!!!

Gorillas ranks second on my coolest games ever made right behind Oregon Trail.

Kitsunexus

  • Hero Member
  • *****
  • Posts: 3911
Re: The programming help thread!
« Reply #4 on: June 01, 2007, 03:17:40 AM »
10 PRINT "ZACK ROX!"
GOTO 10

FM-77

  • Hero Member
  • *****
  • Posts: 2180
Re: The programming help thread!
« Reply #5 on: June 01, 2007, 04:58:11 AM »
Sheeee-it.  I got some programming knowledge for you.

Gorillas on Qbasic is the bomb.  Nibbler, not so much.

Oh how the Radioshack at the mall hated me C:\format bitches!!!

Gorillas ranks second on my coolest games ever made right behind Oregon Trail.

Dude, Nibbler ROCKS!! Especially at speed 99. At least on a 25MHz 386. It was too ****ing fast on 486's.
« Last Edit: June 01, 2007, 05:00:01 AM by Seldane »

offsidewing

  • Hero Member
  • *****
  • Posts: 631
Re: The programming help thread!
« Reply #6 on: June 01, 2007, 05:01:54 AM »
Sheeee-it.  I got some programming knowledge for you.

Gorillas on Qbasic is the bomb.  Nibbler, not so much.

Oh how the Radioshack at the mall hated me C:\format bitches!!!

Gorillas ranks second on my coolest games ever made right behind Oregon Trail.

Dude, Nibbler ROCKS!! Especially when speed 99. At least on a 25MHz 386. It was too ****ing fast on 486's.

heck, we jumped from a 286 with upgraded 640K of RAM right to a blazing 486SX-33 with 4 whole megs of ram and a brusing 1 meg of video ram.  When I got into CAD (and Xwing), we got the clock tripler.

Dark Fact

  • Hero Member
  • *****
  • Posts: 1147
Re: The programming help thread!
« Reply #7 on: June 01, 2007, 06:00:32 AM »
Quote from: Xiphas
I checked the libc man and the above won't work, you'll probably have to use an if structure with floor and ceil of some sort to get it working unless my horrible knowledge of C is making me forget a function in math.h.
The requirement for the question was to have the entire output be in integers.  It also said to "round to the nearest integer".  This is a Chapter 6 question in my textbook that says I should only use the header <stdio.h>, a for loop, and integer values.  I'm not to use any if structures, ceil, floor or extra headers.  That output that you see in my first post is the best I got from it.  However, working out the values on a calculator, some celsius values don't appear properly rounded off like "-6", "-3", and "37".  When I put the values in float, the values are correct.  It's just in int that don't appear correct to me.  If this is the way C interprets the values in int, then there is nothing else I can do with my program.  However, if there is another way to make the values appear properly rounded in int, I would like to know.
Quote from: offsidewing
Sheeee-it.  I got some programming knowledge for you.

Gorillas on Qbasic is the bomb.  Nibbler, not so much.

Oh how the Radioshack at the mall hated me C:\format bitches!!!

Gorillas ranks second on my coolest games ever made right behind Oregon Trail.
Oh my God.  Those games bring back memories! I loved playing Gorillas in QBasic.  It was WORMS before WORMS! :D

Sorry, but I don't see your library card on the books of Ys.  Now, RETURN THEM TO ME!!!

akamichi

  • Sr. Member
  • ****
  • Posts: 403
Re: The programming help thread!
« Reply #8 on: June 01, 2007, 06:33:59 AM »
The requirement for the question was to have the entire output be in integers.  It also said to "round to the nearest integer".  This is a Chapter 6 question in my textbook that says I should only use the header <stdio.h>, a for loop, and integer values.  I'm not to use any if structures, ceil, floor or extra headers.  That output that you see in my first post is the best I got from it.  However, working out the values on a calculator, some celsius values don't appear properly rounded off like "-6", "-3", and "37".  When I put the values in float, the values are correct.  It's just in int that don't appear correct to me.  If this is the way C interprets the values in int, then there is nothing else I can do with my program.  However, if there is another way to make the values appear properly rounded in int, I would like to know.
If you're using ints to do the calculation, then you'll never be able to round the fractional part to the nearest integer because you'll only get whole numbers as a result.  In other words, integer division drops the remainder (truncate).  Now you could do the calculation using floats and then display the floats to make them look like ints.  But that has nothing to do with the calculation, it's just printing them to the screen in a particular format.

However, from what I understand from your initial post, if you're doing straight integer operations, what you have are the answers you should expect when using integer division.

Hope this helps.

Hobo Xiphas

  • Hero Member
  • *****
  • Posts: 529
Re: The programming help thread!
« Reply #9 on: June 01, 2007, 08:38:17 AM »
It also said to "round to the nearest integer".

I can't see how you can get accurate results with the constraints the book gives you.  What you have now is the best you can do.

offsidewing

  • Hero Member
  • *****
  • Posts: 631
Re: The programming help thread!
« Reply #10 on: June 01, 2007, 08:42:35 AM »
Oh my God.  Those games bring back memories! I loved playing Gorillas in QBasic.  It was WORMS before WORMS! :D

There's just something about lobbing bananas across a 14 inch radiation emitter.  Yeah, I played the hell out of it (with a buddy of course) until I found the coolness of Red Storm Rising.  It was only replaced by 688 Attack Sub.

Dark Fact

  • Hero Member
  • *****
  • Posts: 1147
Re: The programming help thread!
« Reply #11 on: June 04, 2007, 04:17:22 PM »
Anyone here know what the math formula is to calculate monthly sales projections? I need it in order to finish the last question on Chapter 6 of my programming textbook.  The whole program for that question is already done.  I just don't know what the monthly sales forecast formula is. ](*,)

Sorry, but I don't see your library card on the books of Ys.  Now, RETURN THEM TO ME!!!

offsidewing

  • Hero Member
  • *****
  • Posts: 631
Re: The programming help thread!
« Reply #12 on: June 04, 2007, 04:28:29 PM »
Anyone here know what the math formula is to calculate monthly sales projections? I need it in order to finish the last question on Chapter 6 of my programming textbook.  The whole program for that question is already done.  I just don't know what the monthly sales forecast formula is. ](*,)

3.14r^2.  or is it y=mx+b?  oh, my favorite. MV=SPANK better know as f=m(dv/dt)=ma

Like my chinese Trig professer always used to say, "I like to see Pi."  Buddy, you and me both.


nat

  • Hero Member
  • *****
  • Posts: 7085
Re: The programming help thread!
« Reply #13 on: June 04, 2007, 04:42:37 PM »
Where the f*ck did this thread come from? It just appeared out of the blue right before my eyes with 11 new messages. Now I know what stevek666 is talking about. To be honest, I just thought he was mental.

This thread is screaming nodtveidt.

Really? I didn't hear anything.

Gorillas ranks second on my coolest games ever made right behind Oregon Trail.

I'll second you there (on the Oregon Trail deal). The Apple // version rules ALL. I still play it sometimes for old time's sake on my Apple //c+. Yes, I am being completely serious. The Macintosh version was OK, but too graphical and hunting wasn't as cool as in the Apple // version; you couldn't walk around the forest and shoot different directions.

Anyone here know what the math formula is to calculate monthly sales projections? I need it in order to finish the last question on Chapter 6 of my programming textbook.  The whole program for that question is already done.  I just don't know what the monthly sales forecast formula is. ](*,)

Yes, if it's as simple as what I think you're asking.

My entire job revolves around doing just that. That's right, I sit at a computer all day tabulating sales data and projecting sales and profit margins for the next week, month, and year. Then I devise new and illegal interesting ways to improve them. And in between when my boss isn't around I log on to www.pcenginefx.com/forums and make fun of people.

(Sales MTD / Days of month that have passed) * number of days in month

For example, to project sales for June as of right now, and assuming my MTD sales are $50,000:

(50,000 / 3 (technically the 4th day isn't over so we won't count it) ) * 30 (30 days in June) = a projection of $500,000 for the month.

offsidewing

  • Hero Member
  • *****
  • Posts: 631
Re: The programming help thread!
« Reply #14 on: June 04, 2007, 04:49:09 PM »

I'll second you there (on the Oregon Trail deal). The Apple // version rules ALL. I still play it sometimes for old time's sake on my Apple //c+. Yes, I am being completely serious. The Macintosh version was OK, but too graphical and hunting wasn't as cool as in the Apple // version; you couldn't walk around the forest and shoot different directions.


The MAC version of hunting licked balls.  Who the heck wants to shoot a 1 frame per minute shotgun from a fixed firing position.  Gimme a rifle, a wagon full of bullets, one color, and bring on the BEARS!

Around my office, I'm the boss.  Anyone caught posting on PCENGINEFX.COM during work hours (like I sometimes do) would immediately get a raise and promoted.  Sadly, no cool people work for me...