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

Username:   Password: 
 RegisterRegister   
 Phone number using -
Index -> Programming, Turing -> Turing Help
Goto page 1, 2  Next
View previous topic Printable versionDownload TopicSubscribe to this topicPrivate MessagesRefresh page View next topic
Author Message
xmdxtreme




PostPosted: Tue May 11, 2004 7:38 pm   Post subject: Phone number using -

Ok one part of my program i want to do this when you type like a phone number 4162340942 the dashes pops up by it self like first 3 digits then a dash pops up:
416-
then you type
416-234- another dash pops up...
like that plz help me i dont have much time Rolling Eyes
btw:if you dont understand sorry for bad english Embarassed
Sponsor
Sponsor
Sponsor
sponsor
Paul




PostPosted: Tue May 11, 2004 8:05 pm   Post subject: (No subject)

code:

var key : string (1)
var num : string := ""
put "Enter your phone number"
for a : 1 .. 10
    getch (key)
    cls
    put "Enter your phone number"
    num += key
    put num ..
    if a mod 3 = 0 and a not= 9 then
        num += "-"
        put "-" ..
    end if
end for
xmdxtreme




PostPosted: Tue May 11, 2004 8:08 pm   Post subject: (No subject)

thank you it helped alot Laughing
xmdxtreme




PostPosted: Tue May 11, 2004 8:36 pm   Post subject: (No subject)

but the user can type letters lol i know for phone numbe its ok but for date i change it to slashes and fixed up the loop and mod for it but they can type letters anyway to prvent that?
Paul




PostPosted: Tue May 11, 2004 8:41 pm   Post subject: (No subject)

well ord("0") is 48 and ord("9") is 57 then
code:

loop
getch (key)
if ord (key) >=48 or ord(key)<=57 then
exit
end if
end loop
xmdxtreme




PostPosted: Tue May 11, 2004 9:29 pm   Post subject: (No subject)

sorry its my first year i dont get this can someone explain this or be a bit more specific sorry man Embarassed
Paul




PostPosted: Wed May 12, 2004 3:24 pm   Post subject: (No subject)

all characters has its on code, ASCII? I think, anyhow, in the code above, it specified that if the code of the numbers entered is between 0 and 9 then, it exits the loops, or else (its not a number) it keeps asking for input.
xmdxtreme




PostPosted: Wed May 12, 2004 4:28 pm   Post subject: (No subject)

it doesnt work i even tried changing the code like this:
code:

var key : string (1)
var num : string := ""
put "Enter your phone number"
loop
getch (key)
exit when ord (key) >=48 or ord(key)<=57
end loop
for a : 1 .. 10
    getch (key)
    cls
    put "Enter your phone number"
    num += key
    put num ..
    if a mod 3 = 0 and a not= 9 then
        num += "-"
        put "-" ..
    end if
end for
we64




PostPosted: Wed May 12, 2004 4:52 pm   Post subject: (No subject)

to prevent not entering letters:
code:

var key : string (1)
var num : string := ""
var a := 1
put "Enter your phone number"

loop
    getch (key)
    cls
    if ord (key) >= 48 and ord (key) <= 57 then
        put "Enter your phone number"
        num += key
        put num ..
        if a mod 3 = 0 and a not= 9 then
            num += "-"
            put "-" ..
        end if
        a += 1
    else
        put "Enter your phone number"
        getch (key)
    end if
    exit when a > 9
end loop
Tony




PostPosted: Wed May 12, 2004 4:56 pm   Post subject: (No subject)

... Confused
code:

var c : string (1)
put "enter your phonenumber"
for i : 1 .. 3
    getch (c)
    put c ..
end for
put "-" ..
for i : 1 .. 3
    getch (c)
    put c ..
end for
put "-" ..
for i : 1 .. 4
    getch (c)
    put c ..
end for
Latest from compsci.ca/blog: Tony's programming blog. DWITE - a programming contest.
Paul




PostPosted: Wed May 12, 2004 5:08 pm   Post subject: (No subject)

I like mine better tony, mine remebers the phone number Wink
xmdxtreme




PostPosted: Wed May 12, 2004 5:12 pm   Post subject: (No subject)

sorry one more thing last question Rolling Eyes i want to store the final phone numbe in a variable how i mean like that ends the you want to use the saved phone number and put it somewhere else.
put phonenumber
I mean i just want to save the final phone number entered including dashes to a variable how?
Paul




PostPosted: Wed May 12, 2004 5:14 pm   Post subject: (No subject)

uh... my code already does it, or rather we64's modified code, just go
code:


put num
xmdxtreme




PostPosted: Wed May 12, 2004 5:17 pm   Post subject: (No subject)

nvm lol edit i asked a stupid question thank all of you guys you helped me alot Laughing
xmdxtreme




PostPosted: Wed May 12, 2004 8:13 pm   Post subject: (No subject)

lol omg another question sorry guys Embarassed backspace doesnt work...
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 2  [ 25 Posts ]
Goto page 1, 2  Next
Jump to:   


Style:  
Search: