Home / Microsoft / Microsoft DOS / Celsius to Farenheit converter
0 Members and 1 Guest are viewing this topic. « previous next »
Pages: [1] - (Bottom) Print
Author Topic: Celsius to Farenheit converter  (Read 3433 times)
jjbtcp
Topic Starter
Beginner



Posts: 100




« on: November 09, 2007, 08:45:36 PM »

I want to make a batch file that can convert Celsius to Farenheit.

Below is the mathematical notation needed to make the conversion.
Celsius * 1.8 + 32

I made a program that does this in C++ but can't figure out how to make one in batch.


Thanks.
IP logged

Regards,
                 Joshua
Zylstra
Moderator
Hacker



Thanked: 37
Posts: 5,274

Certifications: List
Experience: Guru
OS: Windows 7
The Techinator!

Technology News and Information 1
« Reply #1 on: November 09, 2007, 09:14:35 PM »

I dont think this is at all possible in Batch, as Batch is simply for automating lists of tasks. Your better off using a C program, or Qbasic.

( Cool tool: http://www.wbuf.noaa.gov/tempfc.htm )
IP logged

ghostdog74
Mentor



Thanked: 26
Posts: 1,511


« Reply #2 on: November 09, 2007, 09:31:26 PM »

you can do simple arithmetic in batch
see here for example
IP logged

Sidewinder
Guru



Thanked: 97
Posts: 4,342

Experience: Familiar
OS: Windows 7

« Reply #3 on: November 10, 2007, 06:42:57 AM »

Actually, batch code can do simple integer arithmetic. If you use a conversion formula as F = C*9/5+32, you can produce a reasonable approximation.

Code: [Select]
C=78

set /a f=78*9/5+32

F = 172

The batch answer is off by .4 --- a decimal value the batch code can't process.

 8)
IP logged

If you don't know where you are going, any road will get you there

                                                                            -Lewis Carroll
patio
Moderator
Genius



Thanked: 1069
Posts: 11,354

Experience: Beginner
OS: Windows 7


Maud' Dib

« Reply #4 on: November 10, 2007, 02:26:03 PM »

How the heck are ya Sidewinder ? ?

 :)
IP logged

   
"
All generalizations are false, including this one.  "
jjbtcp
Topic Starter
Beginner



Posts: 100




« Reply #5 on: November 10, 2007, 03:25:29 PM »

I guess I'll have to teach my friend C++. I want to help him learn but after you teach someone the basics it's hard to go too much further.
IP logged

Regards,
                 Joshua
Zylstra
Moderator
Hacker



Thanked: 37
Posts: 5,274

Certifications: List
Experience: Guru
OS: Windows 7
The Techinator!

Technology News and Information 1
« Reply #6 on: November 10, 2007, 06:56:02 PM »

Through what I have read about Batch, I never learned once that it could be used for mathematical calculations.
I apologize for my incorrect advice, I had absolutely no idea
IP logged

jjbtcp
Topic Starter
Beginner



Posts: 100




« Reply #7 on: November 10, 2007, 09:02:09 PM »

Don't worry, even though your Information was Incorrect, it still holds relevance - when you said:
Quote
Your better off using a C program, or Q basic.


Thanks guys, But all in all I will just have to forget about making one in Batch.

Sidewinder, Thanks for the code, I know it's only a little bit off but I want it to be precise, Thanks anyway (still might come in useful).
IP logged

Regards,
                 Joshua
yperron
Rookie



Posts: 35




« Reply #8 on: November 13, 2007, 09:27:44 AM »

you just have to mutliply your values by 100 then add the . at the right place

Code: [Select]
@echo off
set C=78
echo C  = %C%

set /a result=%c%*100*9/5+32*100
set /a f1=%result%/100
set /a f2=%result%-%f1%*100

set F=%f1%.%f2%
echo F  = %F%

the output is accurate:
Code: [Select]
C  = 78
F  = 172.40

yp
IP logged

yp
Pages: [1] - (Top) Print 
Home / Microsoft / Microsoft DOS / Celsius to Farenheit converter « previous next »
 


Login with username, password and session length

Old Forum Search | Forum Rules
Copyright © 2010 Computer Hope ® All rights reserved.
Powered by SMF 2.0 RC3 | SMF © 2006–2010, Simple Machines LLC
Page created in 0.097 seconds with 20 queries.