Fortran assignment..Please help

create a program using selective execution

Page 1 of 1

5 Replies - 2439 Views - Last Post: 31 October 2010 - 06:31 AM Rate Topic: -----

#1 Porter5423  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 4
  • Joined: 24-September 08

Fortran assignment..Please help

Post icon  Posted 24 September 2008 - 02:15 PM

Suppose that a gas company bases its charges on consumption according to the following table:

Gas used /Rate

first 70 cubic meters - $5 minimum cost
next 100 cubic meters - 5 cents per cubic meter
next 230 cubic meters - 2.5 cents per cubic meter
above 400 cubic meters - 1.5 cents per cubic meters

Meter readings are four digit numbers that represent cubic meters. Write a program in which the meter reading for the previous month and the current month are entered and then the amount of the bill is calculated. Note:the current reading may be less than the previous one; for example, the previous reading may have been 9897, and the current one is 0103.

have to use case commands not if /then
Thanks!!

This post has been edited by Porter5423: 24 September 2008 - 02:20 PM


Is This A Good Question/Topic? 0
  • +

Replies To: Fortran assignment..Please help

#2 RedSonja  Icon User is offline

  • D.I.C Head
  • member icon

Reputation: 10
  • View blog
  • Posts: 172
  • Joined: 04-September 08

Re: Fortran assignment..Please help

Posted 24 September 2008 - 11:45 PM

Goodness, there are still people learning Fortran! I thought it died long ago. Why are you learning it? Put in some personal details, I am curious...

Anyway, if you want help on this forum, you have to write some code and give it a try first. We don't do your homework, we help fix problems. So have a bash and post it and I will have a look. Maybe there are others out there who have had to do Fortran?

If you never wrote a program before, then copy an old one that works, sort of "hello world", and put in the changes you need. A confession; I have been coding for decades, and I NEVER start with an empty page.
Was This Post Helpful? 0
  • +
  • -

#3 Porter5423  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 4
  • Joined: 24-September 08

Re: Fortran assignment..Please help

Posted 25 September 2008 - 05:28 PM

program consumption
implicit none
real::Previous,Current,Total
real::Price

write(*,*)'insert previous reading, current reading'
read*,Previous,Current

Total= Previous-Current


select case(nint(Total))
case(:70)
Price=5

case(71:171)
Price=.025 


this is what I have so far and I really don't know what i need to do to find the price. I think i might need an equation for the price but i'm not sure.
Was This Post Helpful? 0
  • +
  • -

#4 RedSonja  Icon User is offline

  • D.I.C Head
  • member icon

Reputation: 10
  • View blog
  • Posts: 172
  • Joined: 04-September 08

Re: Fortran assignment..Please help

Posted 26 September 2008 - 02:00 AM

Curses! I de-installed Fortran just yesterday to make room. Still, I will try off the top of my head...

You are on the right track.

Why case 71:171, isn't the second case 70:100? and then to get the amount to bill it's price*cubicmeters, so:

real Bill

case(71:100)
Bill=.025 * Amount

And so on and so forth. A big extra mark for putting IMPLICIT NONE, very good. You still have to handle the meter going over null; if amount <0 then add something ...

Which compiler, which Fortran dialect?

This post has been edited by RedSonja: 26 September 2008 - 02:00 AM

Was This Post Helpful? 0
  • +
  • -

#5 TheFlipside  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 9
  • Joined: 09-August 07

Re: Fortran assignment..Please help

Posted 08 October 2008 - 06:08 AM

Well Sonja... I must confess that on Dutch universities FORTRAN is still used as a programming language in the Engineering Studies.
The reason for this is (I guess anyway) that the particular tools like Finite element packages, CFD code etc. is all written in FORTRAN or uses FORTRAN math modules.
Even MatLab contains a lot of FORTRAN code...
I'm wondering what the future is of this language, like you said it looks likes its dead, but I encounter a lot of FORTRAN in 'state of the art' Fluid-Structure interaction code.
Was This Post Helpful? 0
  • +
  • -

#6 Guest_DeeL*


Reputation:

Re: Fortran assignment..Please help

Posted 31 October 2010 - 06:31 AM

Just did this last month, yes universities are still teaching its students Fortran as an engineering application..
Hope this helps =)
1           PRINT *, "Calculating this month's gas bill"

            PRINT *, "Enter last month's meter reading"
            READ *, lastmonth
            IF (lastmonth<0)THEN
              PRINT *, "Error!"
              GOTO 1
            ELSE
            END IF

            PRINT *, "Enter this month's meter reading"
            READ *, thismonth
            IF (thismonth<0)THEN
              PRINT *, "Error!"
              GOTO 1
            ELSE
            END IF

            IF (thismonth<lastmonth)THEN
              gasusage=((10000-lastmonth)+thismonth)
              PRINT *, "Units of gas used:", gasusage
            ELSE
              gasusage=thismonth-lastmonth
              PRINT *, "Units of gas used:", gasusage
	    END IF

            ! For first 70, 	cost is $05.000
            ! For first 170, 	cost is $10.000 ($0.050 per cubic meter for 100 units)
            ! For first 400,	cost is $15.750 ($0.025 per cubic meter for 230 units)
            ! For above 400,	cost is $00.015         per cubic meter

            IF (gasusage>400)THEN
              bill=(((gasusage-400)*0.015)+15.75)
              PRINT *, "This month's gas bill:   $", bill

            ELSE IF (gasusage>170)THEN
              bill=(((gasusage-170)*0.025)+10)
              PRINT *, "This month's gas bill:   $", bill

            ELSE IF (gasusage>70)THEN
              bill=(((gasusage-70)*0.05)+5)
              PRINT *, "This month's gas bill:   $", bill

            ELSE
              PRINT *, "This month's gas bill:   $5.00"
            END IF


MOD EDIT: When posting code...USE CODE TAGS!!!

:code:
Was This Post Helpful? 0

Page 1 of 1