Need Help Making a Data Base that Accepts Names and Phone #s
Author |
Message |
Beast_
|
Posted: Sat Jan 21, 2006 11:39 pm Post subject: Need Help Making a Data Base that Accepts Names and Phone #s |
|
|
Hey, I have a program that I have to make. I have to store phone numbers and names, then later on I have to print them off in a list. After I list the names and phone numbers off, I must be able to continue from there on and enter more names/phonenumbes, if I wish. Now I am able to store numbers only in the name and phonenumbers field. For some odd reason, Turing isnt allowing me to store actual word's. Just numbers. I've tried specifying the variables to strings, but it is erroring up in the for statement I have made. I must have this problem resolved. If any of you can help me, I would deeply appreciate it. Anyway, here is my progress so far:
var howMany : int
put "How many names and phone numbers?" ..
get howMany
var firstname, lastname, phone : array 1 .. howMany of int
for i : 1 .. howMany
put "Enter first name number ", i, ": " ..
get firstname (i)
put "Enter last name number ", i, ": "..
get lastname (i)
put "Enter phonenumber # ", i, ": "..
get phone (i)
end for
for i : 1 .. howMany
put "Info number ", i, " ",firstname (i)," "..
put lastname (i), " "..
put phone (i)
end for
It just wont allow me to enter names. I need to get this problem solved.
And do you guys know how to enter names which have spaces between them? For example, when the program says enter a name, you enter John Smith and it stores the variable instead of "John." I don't quite remember, but I tried putting a semicolon ( [put; "What is your name?"] after the put statement, but that didnt solve the problem.
thanks for your time. |
|
|
|
|
|
Sponsor Sponsor
|
|
|
Talion
|
Posted: Sun Jan 22, 2006 8:21 am Post subject: (No subject) |
|
|
your array is of int. So therefore everything going into it must be integer as well. make it of string. Then you can enter the numbers and names. oh and use the [code] [syntax] brackets next time.
oh and to enter both names as one variable go 'get name:*' that'll allow you to enter a line of text to one variable. |
|
|
|
|
|
GinoGuy
|
Posted: Sun Jan 22, 2006 11:27 am Post subject: (No subject) |
|
|
Okay, so we can get names now
I don't understand the part where it says "get firstname:*"
When I type that in, it says "illegal get item". :/
ALSO, how can we get it to ask if they want to continue, and start up at the same number they left off?
EDIT: I got the :* thing, but I still needed help with the last part |
|
|
|
|
|
Delos
|
Posted: Sun Jan 22, 2006 12:12 pm Post subject: (No subject) |
|
|
GinoGuy wrote: Okay, so we can get names now
I don't understand the part where it says "get firstname:*"
When I type that in, it says "illegal get item". :/
ALSO, how can we get it to ask if they want to continue, and start up at the same number they left off?
EDIT: I got the :* thing, but I still needed help with the last part
That's not really an easy question to answer, since we haven't seen your code. By 'we' do you mean you are somehow affiliated with Beast_? Or are you coincidentally just doing a similar project?
From what I can figure, you'll have to add a conditional exit to the for loop. |
|
|
|
|
|
GinoGuy
|
Posted: Sun Jan 22, 2006 1:04 pm Post subject: (No subject) |
|
|
code: | var howMany : int
var answer : string
procedure ask
put "How many names and phone numbers? " ..
get howMany
end ask
procedure names
var name, phone : flexible array 1 .. howMany of string
for i : 1 .. howMany
put "Enter name number ", i, ": " ..
get name (i) : *
put "Enter phonenumber # ", i, ": " ..
get phone (i) : *
end for
for i : 1 .. howMany
put "Info number ", i, ": ", name (i), " " ..
put phone (i)
end for
end names
loop
ask
names
put "Would you like to enter more?"
get answer
if answer = "yes" then
cls
ask
names
elsif answer = "no" then
exit
end if
end loop |
And yes, I am affiliated with Beast |
|
|
|
|
|
GinoGuy
|
Posted: Sun Jan 22, 2006 5:18 pm Post subject: (No subject) |
|
|
Before this topic goes far down the list, I have pulled together a bit better code with some remarks to show you what I actually need, and in a bit better detail. Here it is
code: | var howMany : int
var answer : string
% Asks for amount of names to be entered %
put "How many names to be stored?" ..
get howMany
% Gets requested amount of names %
var name : array 1 .. howMany of string
for i : 1 .. howMany
put "Enter name please."
get name (i)
% What I was TRYING to do was record the last number that (i) was at %
% [color=red]var endnum : int := (i)[/color]
end for
% Asks for any more names to be entered %
put "Enter more names?"
get answer
loop
if answer = "yes" then
put "How many more names?"
get howMany
% I want it to go FROM where if left off, to the amount of new names they want %
for i : [color=red]endnum[/color] .. howMany
put "Enter the extra names please"
get name (i) : *
end for
elsif answer = "no" then
exit
end if
end loop |
|
|
|
|
|
|
Beast_
|
Posted: Sun Jan 22, 2006 9:10 pm Post subject: (No subject) |
|
|
I was able to do this, dont know if it is much:
code: | % Adam Baird
% Exam A (With Errors)
% Saturday January 21, 2006
% For Mason
% Purpose: To take and remember names, and allow user to enter more when done.
% Input: A specified amount of names, lastnames, and phone numbers.
% Output: All entered information given
% ----------------------------------------------------------------
% Errors: - Resets Back to 1, instead of last place
% Fixed: - User can enter full name with 1 get statement
% - User can now enter words AND numbers
var howMany : int
var answer : string
var first, HowManyOld, total : int
first := 1
put "How many names and phone numbers? " ..
get howMany
var name, phone : array 1 .. howMany of string
loop
if first = 1 then
HowManyOld := 1
first := 2
else
HowManyOld := HowManyOld + howMany
end if
for i : HowManyOld .. howMany
put "Enter name number ", i, ": " ..
get name (i) : *
put "Enter phonenumber # ", i, ": " ..
get phone (i) : *
end for
total := howMany + HowManyOld - 1
for i : 1 .. total
put name (i), " " ..
put phone (i)
end for
put "Would you like to enter more? 1 = yes, 2 = no"
get answer
if answer = "1" then
cls
elsif answer = "2" then
exit
end if
end loop
put "Exit?"
get answer
if answer = "yes" then
Window.Hide (defWinID)
else
put "Have a nice day!"
end if
[code][/code]
When I say no to exit, it just says "Have a nice day", it doesnt take me back to the beginning. When I want to continue after viewing all of the names/numbers, it just errors. HELP!! :cry: |
|
|
|
|
|
|
|
|