Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
• Status: Solved
• Priority: Medium
• Security: Public
• Views: 275

# A litle problem not so big...

I want to make a program thet will calculate the theard variable thet is not inputed like a number but like ?.
If you can think of a nother way to do this write it.

program speed;
type m1= array ['?'..'?'] of char;
m2=array ['?'..'?'] of char;
m3=array ['?'..'?'] of char;
var  s:array [m1] of real;
t: array [m2] of real;
v: array [m3] of real;

begin                                                     repeat
wrtite ('input varables if, no var. then input ?);
writeln (' input speed v=');
writeln ('input the distanse s=');
writeln('input time in seconds t=');
until ((v=?) and (s>=0) and (t>=0)) or ((v>=0) and (S=?) and (t>=0)) or ((v>=0) and (s>=0) and (t=?));
if v=? then
begin
v:=s/t;
writeln('speed is v=',v:0:2);
end;
if v=0 then writeln( 'pa nisi se pomako');
if s=? then
begin
s:=v*t;
writeln('distanse is s=', s:0:2);
end;
if s=0 then writel ('prijedeni put je 0');
if t=? then
begin
t:=s/v;
writeln (' vrijeme je t=',t:0:2);
end;
end.
0
The_Beeman
• 7
• 3
1 Solution

Commented:
If all the valid inputs are positive, then you could choose any negative number for the "missing value".

Or you could use ? but then you would have to read the items in as strings, then check for ='?', then convert the strings to reals with the Val() function.

0

Author Commented:
O.K. !
this is the thing we are learnin paskal programing in informatic clas and we have done IF  and  CASE until now this val function is a big "what are you talking about" thing.
If you wonder "how the hell did you get to the array and stuf ??" well I tried to make this program thet could do this things (look up) and I am stuck. HELP!!
0

Commented:
This is pretty simple for a human mind to do, but to program it is a pain.  The negative number screen is a good idea, but you _could_ have a negative value for speed or distance (moving backwards).  What you need to do is read all the variables as numbers (real).  Since a speed, time, or distance of zero is going to give an error, use 0 as a "screen" for the "solve for" value.  I don't think you've learned XOR (eXclusive OR), otherwise you could use that for screening.  Then do an if..then of the zero value.  The arrays you declared are not needed.

it may be easier to make the first question be "Which variable do you want to solve for" then do a case..of for the three variables, and then input the other two.

program svt;

var
c:char;
s,v,t:real;

begin
while (c<>'q')AND(c<>'Q') do
case c of
's','S':
{input/output}
'v','V':
{input/output}
't','T':
{input/output}
'q','Q':
writeln('Goodbye');
else
begin
writeln('What var to solve for, use Q to quit');
end;
loop
end.
0

Author Commented:

program svt;
var
c:char;   z,s,v,t:real;
begin
while (c<>'q')AND(c<>'Q') do
case c of
's','S': begin
z:=t*v;
writeln ('put je ',z:0:2);
end;
'v','V':
begin
z:=s/t;
writeln('brzina je' , z:0:2);
end;
't','T':  begin
z:=v/s;
writeln ('vrijeme je ', z:0:2);
end;
'q','Q':
writeln('Goodbye');
else
begin
writeln('What var to solve for, use Q to quit');
end;
loop
end.

this went good when I compiled it. except for this loop thingy the program tels me thet this is a unknown indentifeier (error:3)
0

Author Commented:
I thint I understand what are you meen with this loop.
You want to rotate the program agein but with this wariable when you figure it out I will give you +10 points.
Plz see if I have (I didnt )screened.

thenks
The Beeman
0

Commented:
Uh...yeah, my mistake.  I have no idea why I put "loop" in there.  Just take it out.  I'm doing this on my lunch break at work & I don't have a pascal compiler here.  Two other things:

1)After each time through, you need to set c to something other than q,s,v,t.  Otherwise the program will loop indefinitely on the first variable entered.

2)You need to input the values for the other two variables.  So re-write each input/output as:

begin
writeln('T:');
writeln('V:');
z:=t/v;
writeln('put je',z:0:2);
c:='x';
end;

And so on for the other two input/output cycles.  Go ahead and compile this, and let me know. Hopefully, this is right now.
0

Author Commented:
OK I have done thet but how do I make the program end after calculeiting the var t (for e. g.  writeln('put je',z:0:2);  TO PUT SOME EXIT THING SO THET THE PROGRAM WILL END AFTER WRITING THE Z:0:2 OR GO TO THE END.)
0

Author Commented:
SORRY I forgot the C:='x' (could you explain this to me youst this c what it dose?).
0

Author Commented:
do?
0

Commented:
c is which variable to solve for.  When the program asks for the variable, use Q to exit the program.  By setting it to 'x' it allows the program to loop and ask for another variable to solve for.

If you want it to run just once, then exit, use this:

program svt;
var
c:char;
z,s,v,t:real;
begin
repeat
case c of
's','S': begin
z:=t*v;
writeln ('put je ',z:0:2);
end;
'v','V': begin
z:=s/t;
writeln('brzina je ', z:0:2);
end;
't','T': begin
z:=v/s;
writeln ('vrijeme je ', z:0:2);
end;
else begin
writeln('What var to solve for? ');
end;
until c=('s')OR(c='S')OR(c='v')OR(c='V')OR(c='t')OR(c='T');
end.
0

Author Commented:
OK OK I like the first one was beter and I will stick to it.
My problem is solved and now your points(35+5) you know loop dose not exist.
0

## Featured Post

• 7
• 3
Tackle projects and never again get stuck behind a technical roadblock.