Programming

Programming questions? Ask a programmer for answers ASAP

Ask a Computer Expert,
Get an Answer ASAP!

Hi, I need the algorithm below to change slightly, so that…

Customer Question
Hi, I need the algorithm below...
Hi,

I need the algorithm below to change slightly, so that the first two fields are checked for emptiness in a WHILE loop. I assume that this means that the alert message will have to be the same (eg. Please enter your first and last name). Then I'd like the script for it. Thanks - Kai

IF FirstName == ' '
DISPLAY Please enter your first name
return false

IF LastName == ' '
DISPLAY Please enter your last name
return false

IF EmailAddress == ' '
DISPLAY Please enter your email address
return false

IF Email.value.indexOf("@")= -1
DISPLAY Email address invalid. Please try again
return false

IF Age == ' '
DISPLAY Please enter your age
return false

IF age < 18
DISPLAY Applicants must be at least 18 years old
return false

ENDIF

FOR i = 0 to Age.length - 1
if "0123456789".indexOf(Age.char(i)) = -1
DISPLAY "Please enter numeric"
return false
ENDIF
ENDFOR

DISPLAY 'Please wait while your request is being processed'
return true

END
Submitted: 8 years ago.Category: Programming
Show More
Show Less
Ask Your Own Programming Question
Answered in 1 minute by:
6/10/2010
Programmer: NeOh, Computer Software Engineer replied 8 years ago
NeOh
NeOh, Computer Software Engineer
Category: Programming
Satisfied Customers: 951
Experience: Currently working in web applications.Good Experience in C,VB,ASP,Javascript
Verified

hi,

 

Do you need both alogorithm and script ?

 

Thanks

Shidhin

Ask Your Own Programming Question
Programmer: NeOh, Computer Software Engineer replied 8 years ago

Hi,

 

You mean the WHILE loop has to be used for FirstName and LastName ?

 

So what should be the common alert message ?

 

The better option is to use the OR condition..

 

Please let me know

 

Shidhin

Ask Your Own Programming Question
Customer reply replied 8 years ago
Yes, I need both algorithm and script.
Yes, while loop is for First and Last name fields.
Common alert message "Please enter your first and last name"
It must be a WHILE loop.

Thanks
Programmer: NeOh, Computer Software Engineer replied 8 years ago

Hi,

 

Here is the alogorithm and the script

 

Algorithm:

Code:

WHILE (FirstName == ' ' OR LastName == ' ' )
DISPLAY Please enter your first name and last name
return false
END WHILE
IF EmailAddress == ' '
DISPLAY Please enter your email address
return false
IF Email.value.indexOf("@")= -1
DISPLAY Email address invalid. Please try again
return false
IF Age == ' '
DISPLAY Please enter your age
return false
IF age < 18 DISPLAY Applicants must be at least 18 years old
return false
ENDIF
FOR i = 0 to Age.length - 1
if "0123456789".indexOf(Age.char(i)) = =-1
DISPLAY "Please enter numeric"
return false
ENDIF
ENDFOR
DISPLAY 'Please wait while your request is being processed'
return true
END

 

Script:

Code:



function Validate()
{
var firstname,lastname,email,age;
// Here you've to give the actual ID
firstname=document.getElementById("firstname").value;
lastname=document.getElementById("lastname").value;
email=document.getElementById("email").value;
age=document.getElementById("age").value;
while(firstname==''||lastname=='')
{
alert('Please enter firstname and lastname');
return false;
}
if(email=='')
{
alert('Please enter your email address');
return false;
}
if(email.indexOf('@')==-1)
{
alert('Email address invalid. Please try again');
return false;
}
if(age=='')
{
alert('Please enter your age');
return false;
}
if(age<=18)
{
alert('Applicants must be at least 18 years old');
return false;
}
for(var i=0;age.length;i++)
{
var nums="012345678";
if( nums.indexOf(age.char(i))==-1)
{
   alert('Please enter numerical value for age');
   return false;
}
}
// Final

alert('Please wait while your request is being processed');
return true;
}

 

Thanks

Shidhin

 



Ask Your Own Programming Question
Customer reply replied 8 years ago
That's not really a loop though - I need it to loop. This what I mean (although it's not quite an algorithm yet):

move to the first field
WHILE (not finished ) AND (no error)
If this field is empty - give a message and set an error value
move to the next field
END WHILE
Programmer: NeOh, Computer Software Engineer replied 8 years ago

HI,

 

Could you please explain ? should i need to change the entire algorithm ?

Ask Your Own Programming Question
Customer reply replied 8 years ago
No. There's actually two ways this could be approached, but the important thing is that there is a WHILE loop. It either needs to loop (to check for emptiness) in the first two fields

or

needs to loop to check for emptiness in every field (I guess that means one common error message for any empty field), then check for "@" in email field, numeric in age field, then over 18 in age field.

Thanks
Kai
Programmer: NeOh, Computer Software Engineer replied 8 years ago
ok. i'll make it in the first way. that's easy to correct. i'll change and send you again
Ask Your Own Programming Question
Customer reply replied 8 years ago
Thanks Shidhin
Programmer: NeOh, Computer Software Engineer replied 8 years ago
Hi,

Here is the Modified Algorithm and Script

Algorithm:

Code:

Declare IsName as Boolean
Set IsName=TRUE
WHILE(IsName)
IF (FirstName == ' ')
DISPLAY Please enter your first name
SET IsName=FALSE
IF(LastName == ' ')
DISPLAY Please enter your last name
SET IsName=FALSE
END WHILE
IF(IsName==FALSE)
Return False
END IF
IF EmailAddress == ' '
DISPLAY Please enter your email address
return false
IF Email.value.indexOf("@")= -1
DISPLAY Email address invalid. Please try again
return false
IF Age == ' '
DISPLAY Please enter your age
return false
IF age < 18 DISPLAY Applicants must be at least 18 years old
return false
ENDIF
FOR i = 0 to Age.length - 1
if "0123456789".indexOf(Age.char(i)) = =-1
DISPLAY "Please enter numeric"
return false
ENDIF
ENDFOR
DISPLAY 'Please wait while your request is being processed'
return true
END


Script

Code:

function Validate()
{
var firstname,lastname,email,age,isName=true;
// Here you've to give the actual ID
firstname=document.getElementById("firstname").value;
lastname=document.getElementById("lastname").value;
email=document.getElementById("email").value;
age=document.getElementById("age").value;
while(isName)
{
if(firstname==''){
alert('Please enter firstname ');
isName=false;
}
if(lastname=='')
{
alert('Please enter lastname');
isName=false;
}
}
if(isName==false)
return false;
if(email=='')
{
alert('Please enter your email address');
return false;
}
if(email.indexOf('@')==-1)
{
alert('Email address invalid. Please try again');
return false;
}
if(age=='')
{
alert('Please enter your age');
return false;
}
if(age<=18)
{
alert('Applicants must be at least 18 years old');
return false;
}
for(var i=0;age.length;i++)
{
var nums="012345678";
if( nums.indexOf(age.char(i))==-1)
{
   alert('Please enter numerical value for age');
   return false;
}
}
// Final

alert('Please wait while your request is being processed');
return true;
}




Thanks
Shidhin

Ask Your Own Programming Question
Customer reply replied 8 years ago
Hi Shidhin,
I've been trying to get that bit of code to work without any luck. It's meant to be slipped into another bit of script which creates the form. The fields have already been named "first", "last", "email" and "age". The id of the field can be used in the error message so a loop can occur to check emptiness of all fields. Here's a piece of code that does work but withouth the loop:

function validate()
{
if(document.getElementById("first").value=="")
{
alert("Please enter your first name");
return false;
}
if(document.getElementById('last').value=="")
{
alert("Please enter your last name");
return false;
}

if(document.getElementById('email').value=="")
{
alert("Please enter your email address");
return false;
}

if(document.getElementById('email').value.indexOf("@")==-1)
{
alert("Invalid email address, please try again");
return false;
}

if(document.getElementById('age').value=="")
{
alert("Please enter your age");
return false;
}

if(document.getElementById('age').value<18)
{
alert("Applicants must be at least 18 years of age");
return false;
}

for (i = 0; i < document.getElementById('age').value.length; i++)
{
if("0123456789".indexOf(document.getElementById('age').value.charAt(i)) == -1)
{
alert("Please enter numeric value for age");
return false;
}
}
alert("Please wait while your request is being processed");
return true;
Customer reply replied 8 years ago
Hi Shidhin,

I have a structure to follow for the algorithm to check each felid for emptiness:

SET I = 0
SET errorFlag = False

SET Size = 5

WHILE (I < Size) and (not errorFlag)
IF form(I) is empty -
display a message using the ID of form(I)
SET errorFlag = true
add 1 to I
END WHILE

do you understand this? Can you incorporate it into the algorithm?
Programmer: NeOh, Computer Software Engineer replied 8 years ago

HI,

 

You want the WHILE loop to going through all the fields and do the validation ?

Thanks

Shidhin

Ask Your Own Programming Question
Customer reply replied 8 years ago
No, the while loop should just check for emptiness, ENDWHILE,
then check email for @
then check age for numeric
then check age for =>18

Those last 3 are actually covered, it's just the check for emptiness loop that's the stickler. The fields have already been named "first", "last", "email", "age", there's one more called "state" with a drop down menu (it has a default, so is never empty). The fields appear in that order. The script for the form is already wiritten.

Here's a bit more feedback I've received:

"Two things will stop the loop - finding an empty filed or finishing the loop.
The error should be informative about where it has occured- you can get this info from the field itself. "The id of the field can be used in the error message."

"The purpose of using a WHILE....END WHILE structure is to reference each element of an array
Suppose the array's name is form.

form(0) can be used to reference the first element of the array - the first field on the from"
Programmer: NeOh, Computer Software Engineer replied 8 years ago
HI,

I'm working on this . I'll make the changes and give you

Ask Your Own Programming Question
Was this answer helpful?

How JustAnswer works

step-image
Describe your issueThe assistant will guide you
step-image
Chat 1:1 with a programmerLicensed Experts are available 24/7
step-image
100% satisfaction guaranteeGet all the answers you need
Ask NeOh Your Own Question
NeOh
NeOh
NeOh, Computer Software Engineer
Category: Programming
Satisfied Customers: 951
951 Satisfied Customers
Experience: Currently working in web applications.Good Experience in C,VB,ASP,Javascript

NeOh is online now

A new question is answered every 9 seconds

How JustAnswer works:

  • Ask an ExpertExperts are full of valuable knowledge and are ready to help with any question. Credentials confirmed by a Fortune 500 verification firm.
  • Get a Professional AnswerVia email, text message, or notification as you wait on our site. Ask follow up questions if you need to.
  • 100% Satisfaction GuaranteeRate the answer you receive.

JustAnswer in the News:

Ask-a-doc Web sites: If you've got a quick question, you can try to get an answer from sites that say they have various specialists on hand to give quick answers... Justanswer.com.
JustAnswer.com...has seen a spike since October in legal questions from readers about layoffs, unemployment and severance.
Web sites like justanswer.com/legal
...leave nothing to chance.
Traffic on JustAnswer rose 14 percent...and had nearly 400,000 page views in 30 days...inquiries related to stress, high blood pressure, drinking and heart pain jumped 33 percent.
Tory Johnson, GMA Workplace Contributor, discusses work-from-home jobs, such as JustAnswer in which verified Experts answer people’s questions.
I will tell you that...the things you have to go through to be an Expert are quite rigorous.

What Customers are Saying:

My Expert answered my question promptly and he resolved the issue totally. This is a great service. I am so glad I found it I will definitely use the service again if needed.

One Happy CustomerNew York

Wonderful service, prompt, efficient, and accurate. Couldn't have asked for more. I cannot thank you enough for your help.

Mary C.Freshfield, Liverpool, UK

This expert is wonderful. They truly know what they are talking about, and they actually care about you. They really helped put my nerves at ease. Thank you so much!!!!

AlexLos Angeles, CA

Thank you for all your help. It is nice to know that this service is here for people like myself, who need answers fast and are not sure who to consult.

GPHesperia, CA

I couldn't be more satisfied! This is the site I will always come to when I need a second opinion.

JustinKernersville, NC

Just let me say that this encounter has been entirely professional and most helpful. I liked that I could ask additional questions and get answered in a very short turn around.

EstherWoodstock, NY

Thank you so much for taking your time and knowledge to support my concerns. Not only did you answer my questions, you even took it a step further with replying with more pertinent information I needed to know.

RobinElkton, Maryland

< Previous | Next >

Meet the Experts:

ATLPROG

ATLPROG

Computer Software Engineer

7,677 satisfied customers

MS in IT.Several years of programming experience in Java C++ C C# Python VB Javascript HTML

LogicPro

LogicPro

Computer Software Engineer

7,175 satisfied customers

Expert in C, C++, Java, DOT NET, Python, HTML, Javascript, Design.

unvadim

unvadim

Computer Software Engineer

1,168 satisfied customers

Good knowledge of OOP principles. 3+ years of programming experience with Java and C++. Sun Certified Java Programmer 5.0.

lifesaver

lifesaver

Computer Software Engineer

950 satisfied customers

Several years of intensive programming and application development experience in various platforms.

ehabtutor

ehabtutor

Computer Software Engineer

936 satisfied customers

Bachelor of computer science, 5+ years experience in software development, software company owner

TheDoctor

TheDoctor

Software Engineer

893 satisfied customers

M.S. in Internet Information Systems

The-PC-Guy

The-PC-Guy

Software Engineer

848 satisfied customers

Extensive Knowledge in PHP, MYSQL, CSS & Javascript

< Previous | Next >

Related Programming Questions
Question 3.3. (TCO 7) What task(s) are involved in designing
Question 3.3. (TCO 7) What task(s) are involved in designing a database table? (Points : 2) Naming each record Naming each field Naming each field and providing data types Inserting all the data Quest… read more
LogicPro
LogicPro
Computer Software Engineer
Bachelor of Technology
7,175 satisfied customers
15. (TCO 4) Which VBScript statement represents incrementing
15. (TCO 4) Which VBScript statement represents incrementing the loop counter variable called count? (Points : 5) count = 1 while (count <= 10) count = count + 1 count++ 16. (TCO 4) When a VBScript… read more
ATLPROG
ATLPROG
Computer Software Engineer
Master's Degree
7,677 satisfied customers
1. A department store is having a customer appreciation sale.
1. A department store is having a customer appreciation sale. Depending on the total dollars purchased, the customer could receive a discount on total purchases. You are to develop pseudocode that wil… read more
Raj
Raj
SAP ABAP Consultant
Master\u0027s Degree
27 satisfied customers
I need help with creating a loop to print a table with all
I need help with creating a loop to print a table with all the characters in the user's full and their corresponding ASCii value.… read more
jatechexpert
jatechexpert
Master\u0027s Degree
1 satisfied customers
Design your own Java application that displays a form for a
Design your own Java application that displays a form for a user to enter their firstname, lastname and Age. The form should also include a JButton and a JTextField. When the user clicks on the JButto… read more
ATLPROG
ATLPROG
Computer Software Engineer
Master's Degree
7,677 satisfied customers
Complete the file final.cpp. In this file is the familiar Person
Complete the file final.cpp. In this file is the familiar Person class borrowed from previous work. There are also two new classes: Student and Students. As is shown in the comments, there are unfinis… read more
LogicPro
LogicPro
Computer Software Engineer
Bachelor of Technology
7,175 satisfied customers
C++ STL class set Video Rental Store....Please Help!!!
C++ STL class set Video Rental Store....Please Help!!!! This question comes from Data Structure using C++ D.S. Malik Edition 2, here is the link to the source code that needs to be redone, http://www.… read more
Danielle-Moderator
Danielle-Moderator
5 satisfied customers
Can you please help me rewrite the following algorithm using
Can you please help me rewrite the following algorithm using a WHILE loop weeklyRainfall = 0 ; FOR counter = 1 TO 7 Get rainfall ; weeklyRainfall = weeklyRainfall + rainfall ; ENDFOR Display weeklyRai… read more
ATLPROG
ATLPROG
Computer Software Engineer
Master's Degree
7,677 satisfied customers
Assignment (part A): Your goal is to solve the following
Assignment (part A): Your goal is to solve the following simple programming exercise. Using a FOR loop, write an algorithm that displays the squares of the numbers 1 to 10 to console output. Thought p… read more
jatechexpert
jatechexpert
Master\u0027s Degree
1 satisfied customers
For LogicPro only, Hi, I could use your help with another
For LogicPro only, Hi, I could use your help with another one, its due in 26 hours. Thank you. Create a package named part1. Using this package, create the class StringTest and implement the specified… read more
LogicPro
LogicPro
Computer Software Engineer
Bachelor of Technology
7,175 satisfied customers
Use algorithm for the Bank program definition to create a program
Use algorithm for the Bank program definition to create a program that will solve the local department store's need for a monthly pay checking generating program using methods. Some processing require… read more
ATLPROG
ATLPROG
Computer Software Engineer
Master's Degree
7,677 satisfied customers
I just want to compare my answers with yours before I turn
I just want to compare my answers with yours before I turn in my assignment. Convert the following for loop to a while loop. input workforceSize for workerNumber = 1 to workforceSize read workerRecord… read more
Ansh P.
Ansh P.
System Analyst
Bachelor\u0027s Degree
6,393 satisfied customers
Hi Ramesh, Thanks for your help, but I would still like
Hi Ramesh, Thanks for your help, but I would still like an algorithm (pseudocode) for this issue. Are you familiar with pseudocode or don't you use it at all? Thanks Kai… read more
LogicPro
LogicPro
Computer Software Engineer
Bachelor of Technology
7,175 satisfied customers
Hi, I need a pseudocode for the following, using a WHILE loop An
Hi, I need a pseudocode for the following, using a WHILE loop: An online registration form (the form already exists) and contain fields "First name", "Last name", "Email", "State", & "Age" and a drop … read more
Ramesh Patil
Ramesh Patil
Master's Degree
417 satisfied customers
Write a script that will prompt for the users first name and
Write a script that will prompt for the user's first name and store it in a variable. Then prompt for the last name and store it in a variable. Finally, display the stored information in the format “Y… read more
LogicPro
LogicPro
Computer Software Engineer
Bachelor of Technology
7,175 satisfied customers
How do I make // This program illustrates how to read strings
How do I make // This program illustrates how to read strings and numeric data. import java.util.*; public class Example2_17 { static Scanner console = new Scanner(System.in); public static void main(… read more
Raj
Raj
SAP ABAP Consultant
Master\u0027s Degree
27 satisfied customers
Part 1 Implement the Java code for the online eFax subscription
Part 1: Implement the Java code for the online eFax subscription inheritance hierarchy in Phase 1 IP. Write a test application that instantiates at least one of each subclass type. Your test applicati… read more
Rafael Martins
Rafael Martins
System Developer
446 satisfied customers
Hello - I am implement some code (a contribution) but am having
Hello - I am implement some code (a contribution) but am having a problem in that when the string I need to use is returned (in this case an email address) the '@' sign is being stripped out. I have s… read more
NeOh
NeOh
Computer Software Engineer
Bachelor's Degree
951 satisfied customers
Disclaimer: Information in questions, answers, and other posts on this site ("Posts") comes from individual users, not JustAnswer; JustAnswer is not responsible for Posts. Posts are for general information, are not intended to substitute for informed professional advice (medical, legal, veterinary, financial, etc.), or to establish a professional-client relationship. The site and services are provided "as is" with no warranty or representations by JustAnswer regarding the qualifications of Experts. To see what credentials have been verified by a third-party service, please click on the "Verified" symbol in some Experts' profiles. JustAnswer is not intended or designed for EMERGENCY questions which should be directed immediately by telephone or in-person to qualified professionals.

Disclaimer: Information in questions, answers, and other posts on this site ("Posts") comes from individual users, not JustAnswer; JustAnswer is not responsible for Posts. Posts are for general information, are not intended to substitute for informed professional advice (medical, legal, veterinary, financial, etc.), or to establish a professional-client relationship. The site and services are provided "as is" with no warranty or representations by JustAnswer regarding the qualifications of Experts. To see what credentials have been verified by a third-party service, please click on the "Verified" symbol in some Experts' profiles. JustAnswer is not intended or designed for EMERGENCY questions which should be directed immediately by telephone or in-person to qualified professionals.

Show MoreShow Less

Ask Your Question

x