Programming C, C++, Java, PHP, Ruby, Turing, VB
Computer Science Canada 
Programming C, C++, Java, PHP, Ruby, Turing, VB  

Username:   Password: 
 RegisterRegister   
 VAR topic
Index -> Programming, Turing -> Turing Help
View previous topic Printable versionDownload TopicSubscribe to this topicPrivate MessagesRefresh page View next topic
Author Message
nin




PostPosted: Tue Nov 28, 2006 6:13 pm   Post subject: VAR topic

I need help on this one my code is not working at all there is an error and i dont noe how to fix it 0.o..... the error is bolded and underlined.... the program needs to convert distance to miles or yards and it says on the paper "You may need to errortrap the input!"... and we cant use mod ...
_____________________________________________________________
%This program will convert a distance from miles to yards or yards to miles

%Declaration statement
var mOry : string
var yOrm : string
var distance : real
var answer : real
var number : real


%Program Title
locate (1, 34)
put "Converter"

%Program introduction
locate (3, 1)
put "This program allows you to convert distance to miles or yards."

%User Input and errortrap

locate (5, 1)
put "When you enter the type of measurement, please put either m or y."
put "m being miles and y being yards."
locate (7, 1)
put "Make sure that m or y is not capitalize."

locate (9, 1)
put "Please enter the type of measurement, m or y: " ..
get mOry
locate (10, 1)
put "Please enter the distance: " ..


%Processing
if mOry = "m" or mOry = "M" then
answer := number * 1760
mOry := "miles"
yOrm := "yards"
else
answer := number / 1760
mOry := "yards"
yOrm := "miles"
end if
Sponsor
Sponsor
Sponsor
sponsor
Ultrahex




PostPosted: Tue Nov 28, 2006 6:47 pm   Post subject: (No subject)

if you havent noticed yet the error is

"Variable Has No Value"

This means one of the variables it is setting to has no value yet

(in your case NUMBER has not been set to anything)
you are missing your get number after asking for the distance

Hope This Helps
uberwalla




PostPosted: Tue Nov 28, 2006 6:50 pm   Post subject: (No subject)

is this what you mean? ...

code:

var mOry : string
var yOrm : string
var distance : real

locate (1, 34)
put "Converter"

locate (3, 1)
put "This program allows you to convert distance to miles or yards."

locate (5, 1)
put "When you enter the type of measurement, please put either m or y."
put "m being miles and y being yards."
locate (7, 1)
put "Make sure that m or y is not capitalize."

locate (9, 1)
put "Please enter the type of measurement, m or y: " ..
get mOry
locate (10, 1)
put "Please enter the distance: " ..
get distance

if mOry = "m" or mOry = "M" then
    put distance, " Miles Equals " ..
    distance := distance * 1760
    put distance, " Yards."
else
    put distance, " Yards Equals " ..
    distance := distance / 1760
    put distance, " Miles."
end if


the error in your code is that u never got the distance and never put it to output either.

also...

code:

var answer : real
var number : real


those two lines are kind of pointless
1) you dont even ever use them
2) u can reuse distance as u can see in what i did.

so i hope this is what u were needing help with/looking for.
nin




PostPosted: Tue Nov 28, 2006 8:28 pm   Post subject: (No subject)

thank you umberwalla =) and the person above umberwalla.... =D
uberwalla




PostPosted: Tue Nov 28, 2006 8:30 pm   Post subject: (No subject)

its "uberwalla" but your welcome Razz

and its "Ultrahex" Razz he has a name too
Display posts from previous:   
   Index -> Programming, Turing -> Turing Help
View previous topic Tell A FriendPrintable versionDownload TopicSubscribe to this topicPrivate MessagesRefresh page View next topic

Page 1 of 1  [ 5 Posts ]
Jump to:   


Style:  
Search: