Newbie thing - Programmers Heaven

#### Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

# Newbie thing

Posts: 4Member
Ok, I'm having a little trouble with this one stupid program I'm making. It is basically an Ohm's Law calculator; it asks what the user wants to calculate..well, you'll see. The problem I'm having is that it won't compile correctly, it keeps saying stupid stuff like: "Error: Incompatible types: got "CHAR" expected "S80REAL" " on lines 8,18,28 and the other error says "Fatal: Syntax error, . expected but end of file found" Here's the code.
[code]
program OHMSLAWONE (input, output);
var R, V, I, choice1, choice2: real;
choice3, choice4, y, n: char;
begin
writeln( 'Please enter what you would like to calculate' );
writeln( 'Enter r for resistance, v for voltage, and i for current' );
readln( choice3 ); {determines what the user wants to do}
if choice3 = r then
begin {finds resistance}
writeln( 'Please enter a value for voltage' );
writeln( 'Please enter a value for current' );
R := choice1 / choice2;
writeln( 'The resistance you are looking for is ', R, ' Ohms ' )
end
else
if choice3 = v then {finds voltage}
begin
writeln( 'Please enter a value for current' );
writeln( 'Please enter a value for resistance' );
V := choice1 * choice2;
writeln( 'The voltage you are looking for is ', V, ' Volts ' );
end
else
if choice3 = i then
begin {finds current}
writeln( 'Please enter a value for voltage' );
writeln( 'Please enter a value for resistance' );
I := choice1 / choice2;
writeln( 'The current you are looking for is ', I, ' Amps ' )
end
end
[/code]
It would be really great if someone could help me with this. By the way, I'm using Dev-Pascal (the IDE from Bloodshed that uses the FreePascal compiler for those of you who don't know). TIA

«1

• Posts: 323Member
: Ok, I'm having a little trouble with this one stupid program I'm making. It is basically an Ohm's Law calculator; it asks what the user wants to calculate..well, you'll see. The problem I'm having is that it won't compile correctly, it keeps saying stupid stuff like: "Error: Incompatible types: got "CHAR" expected "S80REAL" " on lines 8,18,28 and the other error says "Fatal: Syntax error, . expected but end of file found" Here's the code.
: [code]
: program OHMSLAWONE (input, output);
: var R, V, I, choice1, choice2: real;
: choice3, choice4, y, n: char;
: begin
: writeln( 'Please enter what you would like to calculate' );
: writeln( 'Enter r for resistance, v for voltage, and i for current' );
: readln( choice3 ); {determines what the user wants to do}
: if choice3 = r then
: begin {finds resistance}
: writeln( 'Please enter a value for voltage' );
: writeln( 'Please enter a value for current' );
: R := choice1 / choice2;
: writeln( 'The resistance you are looking for is ', R, ' Ohms ' )
: end
: else
: if choice3 = v then {finds voltage}
: begin
: writeln( 'Please enter a value for current' );
: writeln( 'Please enter a value for resistance' );
: V := choice1 * choice2;
: writeln( 'The voltage you are looking for is ', V, ' Volts ' );
: end
: else
: if choice3 = i then
: begin {finds current}
: writeln( 'Please enter a value for voltage' );
: writeln( 'Please enter a value for resistance' );
: I := choice1 / choice2;
: writeln( 'The current you are looking for is ', I, ' Amps ' )
: end
: end
: [/code]
: It would be really great if someone could help me with this. By the way, I'm using Dev-Pascal (the IDE from Bloodshed that uses the FreePascal compiler for those of you who don't know). TIA
:

It looks like a homework so I'll be short:

1. First error is caused by IF statements (all 3 of them):
[code]
if choice3 = r { just an example }
[/code]

choice3 is declared as CHAR but what is [b]variable r[/b] in this case? It is not declared.

2. program should end with DOT:
[code]
begin
:
:
:
end. { note the dot after END }
[/code]

Iby

• Posts: 323Member

: It looks like a homework so I'll be short:
:
: 1. First error is caused by IF statements (all 3 of them):
: [code]
: if choice3 = r { just an example }
: [/code]
:
: choice3 is declared as CHAR but what is [b]variable r[/b] in this case? It is not [b]declared as CHAR[/b] (It is REAL).
:
: 2. program should end with DOT:
: [code]
: begin
: :
: :
: :
: end. { note the dot after END }
: [/code]
:
: Iby
:
:
:

• Posts: 323Member

: It looks like a homework so I'll be short:
:
: 1. First error is caused by IF statements (all 3 of them):
: [code]
: if choice3 = r { just an example }
: [/code]
:
: choice3 is declared as CHAR but what is [b]variable r[/b] in this case? It is not [b]declared as CHAR[/b] (It is REAL).
:
: 2. program should end with DOT:
: [code]
: begin
: :
: :
: :
: end. { note the dot after END }
: [/code]
:
: Iby
:
:
:

• Posts: 323Member

: It looks like a homework so I'll be short:
:
: 1. First error is caused by IF statements (all 3 of them):
: [code]
: if choice3 = r { just an example }
: [/code]
:
: choice3 is declared as CHAR but what is [b]variable r[/b] in this case? It is not [b]declared as CHAR[/b] (It is REAL).
:
: 2. program should end with DOT:
: [code]
: begin
: :
: :
: :
: end. { note the dot after END }
: [/code]
:
: Iby
:
:
:

• Posts: 4Member
:
: : It looks like a homework so I'll be short:
: :
: : 1. First error is caused by IF statements (all 3 of them):
: : [code]
: : if choice3 = r { just an example }
: : [/code]
: :
: : choice3 is declared as CHAR but what is [b]variable r[/b] in this case? It is not [b]declared as CHAR[/b] (It is REAL).
: :
: : 2. program should end with DOT:
: : [code]
: : begin
: : :
: : :
: : :
: : end. { note the dot after END }
: : [/code]
: :

Thanks for replying so fast, Iby. I guess I didn't declare r, v, and i. and I wish the website I'm learning this stuff on would have said that thing about the end. Either that or I was just reading it too fast. By the way, It's not homework, but I could use in my telecommunications class since we're studying electronics. Nothing big, just learning the basics. Ok, another question. How would you do make the program go to the beginning if the user wants to calculate something else? I was thinking of something like:
[code]
writeln('Would you like to calculate something else?');
if choice4 = y then
repeat
else
{don't know what to put here.}
[/code]
Thanks again. Laters.
Baut

• Posts: 4Member
: Ok, I'm having a little trouble with this one stupid program I'm making. It is basically an Ohm's Law calculator; it asks what the user wants to calculate..well, you'll see. The problem I'm having is that it won't compile correctly, it keeps saying stupid stuff like: "Error: Incompatible types: got "CHAR" expected "S80REAL" " on lines 8,18,28 and the other error says "Fatal: Syntax error, . expected but end of file found." I'm guessing the duplicate thing is becuase there are two versions of the same char, e.g., R and r. Here's the code.
: [code]
: program OHMSLAWONE (input, output);
: var R, V, I, choice1, choice2: real;
: choice3, choice4, y, n: char;
: begin
: writeln( 'Please enter what you would like to calculate' );
: writeln( 'Enter r for resistance, v for voltage, and i for current' );
: readln( choice3 ); {determines what the user wants to do}
: if choice3 = r then
: begin {finds resistance}
: writeln( 'Please enter a value for voltage' );
: writeln( 'Please enter a value for current' );
: R := choice1 / choice2;
: writeln( 'The resistance you are looking for is ', R, ' Ohms ' )
: end
: else
: if choice3 = v then {finds voltage}
: begin
: writeln( 'Please enter a value for current' );
: writeln( 'Please enter a value for resistance' );
: V := choice1 * choice2;
: writeln( 'The voltage you are looking for is ', V, ' Volts ' );
: end
: else
: if choice3 = i then
: begin {finds current}
: writeln( 'Please enter a value for voltage' );
: writeln( 'Please enter a value for resistance' );
: I := choice1 / choice2;
: writeln( 'The current you are looking for is ', I, ' Amps ' )
: end
: end
: [/code]
: It would be really great if someone could help me with this. By the way, I'm using Dev-Pascal (the IDE from Bloodshed that uses the FreePascal compiler for those of you who don't know). TIA
:

• Posts: 6,349Member
: : Ok, I'm having a little trouble with this one stupid program I'm making. It is basically an Ohm's Law calculator; it asks what the user wants to calculate..well, you'll see. The problem I'm having is that it won't compile correctly, it keeps saying stupid stuff like: "Error: Incompatible types: got "CHAR" expected "S80REAL" " on lines 8,18,28 and the other error says "Fatal: Syntax error, . expected but end of file found." I'm guessing the duplicate thing is becuase there are two versions of the same char, e.g., R and r. Here's the code.
: : [code]
: : program OHMSLAWONE (input, output);
: : var R, V, I, choice1, choice2: real;
: : choice3, choice4, y, n: char;
: : begin
: : writeln( 'Please enter what you would like to calculate' );
: : writeln( 'Enter r for resistance, v for voltage, and i for current' );
: : readln( choice3 ); {determines what the user wants to do}
: : if choice3 = r then { <==== you forgot to surround the r with ''. It now tries to compare the choice3 variable with the value in the variable r }
: : begin {finds resistance}
: : writeln( 'Please enter a value for voltage' );
: : writeln( 'Please enter a value for current' );
: : R := choice1 / choice2;
: : writeln( 'The resistance you are looking for is ', R, ' Ohms ' )
: : end
: : else
: : if choice3 = v then {finds voltage}
: : begin
: : writeln( 'Please enter a value for current' );
: : writeln( 'Please enter a value for resistance' );
: : V := choice1 * choice2;
: : writeln( 'The voltage you are looking for is ', V, ' Volts ' );
: : end
: : else
: : if choice3 = i then
: : begin {finds current}
: : writeln( 'Please enter a value for voltage' );
: : writeln( 'Please enter a value for resistance' );
: : I := choice1 / choice2;
: : writeln( 'The current you are looking for is ', I, ' Amps ' )
: : end
: : end
: : [/code]
: : It would be really great if someone could help me with this. By the way, I'm using Dev-Pascal (the IDE from Bloodshed that uses the FreePascal compiler for those of you who don't know). TIA
: :
:
:

• Posts: 323Member

[code]
var R, V, I, ..... : real; { [b]r[/b] is declared as [b]real[/b]}
choice3, ..... : char; { [b]choice3[/b] is declared as [b]char[/b] }

;
;
;
;

if choice3 = r { see the problem now? }

[/code]

Iby

• Posts: 323Member
Hi again,

Maybe I should have mentioned that in pascal
capitalization doesn't matter. This means that
'R' and 'r' are the same variable.
You have declared 'R' as REAL. That's the problem.

Ohm's law calculator is such simple thing that
I would rather just ask for all variables and
display all possible results.

[code]
program ohms_law;

var u,i,r:real;
value:string;
code:integer;

begin
repeat
U:=0;
I:=0;
R:=0;
writeln;
writeln;
writeln('Calculator bla bla...');
writeln('Enter values as prompted:');
if (U=0) and (R=0) then halt;
if U*R=0 then begin
end else I:=U/R;
if I*R<>0 then U:=I*R;
if I*U<>0 then R:=U/I;
writeln;
writeln('U:=',U:1:3);
writeln('R:=',R:1:3);
writeln('I:=',I:1:3);
until (U*I*R)=0;
end.
[/code]

Iby

• Posts: 4Member
: Hi again,
:
:
: Maybe I should have mentioned that in pascal
: capitalization doesn't matter. This means that
: 'R' and 'r' are the same variable.
: You have declared 'R' as REAL. That's the problem.
:
: Ohm's law calculator is such simple thing that
: I would rather just ask for all variables and
: display all possible results.
:
: [code]
: program ohms_law;
:
: var u,i,r:real;
: value:string;
: code:integer;
:
: begin
: repeat
: U:=0;
: I:=0;
: R:=0;
: writeln;
: writeln;
: writeln('Calculator bla bla...');
: writeln('Enter values as prompted:');
: if (U=0) and (R=0) then halt;
: if U*R=0 then begin
: end else I:=U/R;
: if I*R<>0 then U:=I*R;
: if I*U<>0 then R:=U/I;
: writeln;
: writeln('U:=',U:1:3);
: writeln('R:=',R:1:3);
: writeln('I:=',I:1:3);
: until (U*I*R)=0;
: end.
: [/code]
:
: Iby
:
:
:

Well, all that stuff is kind of beyond my current knowledge and I was still having trouble with my version, but I copied yours, compiled, and it obviously worked. Thanks for the help..

«1