| View previous topic :: View next topic |
| Author |
Message |
oib111 I post too much
Reputation: 0
Joined: 02 Apr 2007 Posts: 2947 Location: you wanna know why?
|
Posted: Fri Jun 22, 2007 10:34 pm Post subject: What is wrong with this code? |
|
|
Ok, well I wanted to make a farenheit to celcius converter and vise versa. But there seems to be something wrong with my code that I just can't seem to fix. So, can you guys help me with it? Here is the code. Btw it is in pascal. Now I know you guys know delphi, so this shouldn't be that hard...
| Code: |
program FarenheitToCelcius_CelciusToFarenheit;
uses crt;
var i : char;
procedure FarenheitToCelcius;
var F,C : integer;
begin
clrscr;
writeln('Please enter the temperature in farenheit.');
readln(F);
C:=(F-32)*5/9;
writeln('The temperature in celcius is ',C,'.');
readln;
end;
procedure CelciusToFarenheit;
var F,C : integer;
clrscr;
writeln('Please enter the temperature in celcius.');
readln(C);
F:=(C*9)/5+32;
writeln('The temperature in farenheit is ',F,'.');
readln;
end;
begin
var F,C : string;
i : char;
F:='F';
C:='C';
clrscr;
writeln('Welcome to the Temperature Converter by oib.');
writeln('If you would like to convert farenheit to celcius press F.');
writeln('If you would like to convert celcius to farenheit press C.');
readln(i);
if (i<>'F') and (i<>'C') then
begin
writeln('Invalid choice, your choices are F and C.');
end;
else if (i = 'F') then
begin
FarenheitToCelcius;
end;
else
begin
CelciusToFarenheit;
end;
end.
|
_________________
| 8D wrote: |
cigs dont make people high, which weed does, which causes them to do bad stuff. like killing |
|
|
| Back to top |
|
 |
appalsap Moderator
Reputation: 0
Joined: 27 Apr 2006 Posts: 6753 Location: Pakistan
|
Posted: Fri Jun 22, 2007 10:37 pm Post subject: |
|
|
| you shouldn't be using integers for this.
|
|
| Back to top |
|
 |
SkatSkat Grandmaster Cheater
Reputation: 0
Joined: 30 Oct 2006 Posts: 648
|
Posted: Fri Jun 22, 2007 11:19 pm Post subject: |
|
|
What's the problem?
_________________
"We're betting everything on ourselves tonight" - The Bouncing Souls
 |
|
| Back to top |
|
 |
Uzeil Moderator
Reputation: 6
Joined: 21 Oct 2006 Posts: 2411
|
Posted: Sat Jun 23, 2007 12:30 am Post subject: |
|
|
You use blocks for no apparent reason, you apply chars to string varables when they are neither used or necessary as STRINGs, you don't control what happens after the string for invalid input, and since the only difference is the math and string and you only call it from one location, you only need one algo that doesn't need to be seperated to a procedure and can be based on if statements depending on a boolean set by their input.
TADAA
_________________
|
|
| Back to top |
|
 |
|