Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Multiple variable input <URGENT>

Status
Not open for further replies.

sr00014

Technical User
Nov 28, 2007
1
GB
Hi. Im stuck and I dunno what to do. Basicaly i need to creat a program that will convert temperature, between C,K, and F, depending on what i input. its fairly simple however it needs to be input in the form XU,

where x is the temperature and U the units, ie in the form 26C or 45F or 269K

its not a problem when i read units and temperature seperately but i ideally need to read it when its input as either say 26k or 26 k (i can have a space between the values if it makes it easier)

thanks



 
1) Input the line as a character string
Code:
character*80:: tempbase
read (*,*) tempbase
2) Read the value
Code:
integer:: temp
read (tempbase, *) temp
3) Work out what the unit is
Code:
integer, parameter:: UNKNOWN=0, CELSIUS=1, FARENHEIT=2, KELVIN=3
integer:: base
character*1:: ch
base = UNKNOWN
do ii = 1, 80
   ch = temp(ii:ii)
   if (ch .eq. 'K') base = KELVIN
   if (ch .eq. 'F') base = FARENHEIT
   if (ch .eq. 'C') base = CELSIUS
   if (base .ne. UNKNOWN) goto 999
enddo
999 continue
Now do your conversion based on base.
 
Think I got a bit of this wrong. Do part 3 before part 2 and change the loop to
Code:
base = UNKNOWN
do ii = 1, 80
   ch = tempbase(ii:ii)
   if (ch .eq. 'K') base = KELVIN
   if (ch .eq. 'F') base = FARENHEIT
   if (ch .eq. 'C') base = CELSIUS
   if (base .ne. UNKNOWN) then
       tempbase(ii:ii) = ' '
       exit
   end if
enddo
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top