Solved

# A litle problem not so big...

Posted on 2003-02-23
Medium Priority
267 Views
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
Question by:The_Beeman
[X]
###### Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

• Help others & share knowledge
• Earn cash & points
• 7
• 3

LVL 22

Expert Comment

ID: 8003557
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 Comment

ID: 8004263
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

Expert Comment

ID: 8022275
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 Comment

ID: 8031926

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 Comment

ID: 8031968
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

Accepted Solution

Adam Mason earned 160 total points
ID: 8035145
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 Comment

ID: 8044314
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 Comment

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

Author Comment

ID: 8044358
do?
0

Expert Comment

ID: 8044963
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 Comment

ID: 8047985
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

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Check out the latest tech news, community articles, and expert highlights in August's newsletter.
What's worse than having your data encrypted by ransomware? Getting attacked by a so-called "wiper," which simply destroys the data and offers you no hope of ever seeing it again.
If youāve ever visited a web page and noticed a cool font that you really liked the look of, but couldnāt figure out which font it was so that you could use it for your own work, then this video is for you! In this Micro Tutorial, you'll learn yoā¦
In this video, Percona Solutions Engineer Barrett Chambers discusses some of the basic syntax differences between MySQL and MongoDB. To learn more check out our webinar on MongoDB administration for MySQL DBA: https://www.percona.com/resources/weā¦
###### Suggested Courses
Course of the Month8 days, 16 hours left to enroll