# Visual Logic (Visual Basic)

Discussion in 'OT Technology' started by Qckrun, Apr 9, 2005.

1. ### QckrunNew Member

Joined:
Dec 29, 2004
Messages:
6,172
0
Location:
CA
Does anyone have any experience with Visual Logic Programming? Its essentially Visual Basic but a little bit different. I have an assignment due on tuesday, and I am complete lost and I do not have any idea what to do. Please post if you can help, or know a little bit about it. I will post up the assignment if there are willingly people to help me.

Thanks,

Chris

2. ### QckrunNew Member

Joined:
Dec 29, 2004
Messages:
6,172
0
Location:
CA
Here is the assignment. The old program is at the bottom.

First Change: Using a loop for the entry of the (three) games.

In the previous Freegumph algorithms, you have used three separate variables for the three games. This was fine. Now consider what might happen if the National Inter-Collegiate Freegumph Society decided that you should use four games for calculating handicaps, or five, or two, or whatever. It would take several changes in your algorithm to accommodate this change in the rules.

Note: The number of games to be used for your algorithm is THREE! We are not changing that, nor should the number of games to use become an input to the algorithm. However, any time you develop a program, you want to make the program MAINTAINABLE, meaning that if changes need to be made later, you want those changes to be made easily and with less likelihood that the changes will cause errors elsewhere in the program. So what you are being asked to do here is to come up with an approach in your algorithm such that, should NICFS decided to change the number of games to be used for calculating handicaps to four, or two, or whatever a programmer could make that change with a minimum of effort.

You should be using a named constant for the number of games to be used. Now revise the logic for obtaining the total of the games : use a loop for inputting the scores and accumulating the total.

NOTE: The loop is calculate, the total could logically be a counter-controlled WHILE loop or a FOR Loop, but a FOR loop is the loop of choice for this type of program. USE A FOR LOOP!

Second Change: Handling more than one freegumpher.

The major problem with your earlier algorithm is that you had to run it a separate time for every freegumpher. This time, you’ll use a loop to allow entry of one Freegumpher’s date after another.

The basic structure will include a loop around the whole set of logic you had previously used. It will being by getting a response to a brand new question, namely, whether or not there is a Freegumpher whose handicap they wish to determine. Note that this is s priming read for a WHILE LOOP. (This response is also going to be a Yes or a No, but it is unrelated to the issue of whether the Freegumpher has played three games.) Hopefully, you immediately recognize this as a case of the “Ask the user when to stop” pre-test loop.

At the very end of the loop, when your old algorithm would have been ready to quit, your algorithm will again get a response from the user as to whether there is ANOTHER Freegumpher whose handicap they wish to determine. When you get the response, you’re ready to go back to the top of the loop. (This, of course, is the loop read).

It is REQUIRED that you use this A priming read approach for the algorithm, since you want to allow the user to get out without entering any data if she finds that she has gotten into the program without any Freegumphers. (Imagine that she starts the program at the beginning of the day, then waits for Freegumphers to show up with scores. At the end of the day, she enters the “No” to end the program. It is remotely possible that no Freegumphers at all show up during one of the days. Your pre-test loop is ready-made for this occasion.)

Please consider this: Given this type of loop construction, with a WHILE condition that says something like Awhile GotAPlayer = “Y”, what happens if the user makes a mistake and enters something other than a “Y” or an “N”? I don’t think it is necessary to use a data validation loop to deal with this one—if they answer anything other than “Y”, the algorithm ends. That’s not a serious problem. If they meant to say Yes, but accidentally hit the wrong key, all they have to do is start over (i.e., run the algorithm again) for the next player.

Its not always that easy, sometimes there are serious consequences if the loop terminates to early, due to an improper keystroke. In such a situation, perhaps your loop condition should be:

While GotAPlayer <> “N”

Now an invalid entry will cause the loop to iterate again!

If that, too, is unacceptable, you may need to go to a data validation loop for that input. In this exercise, you aren’t required to do that. Just stick with: while GotAPlayer =”Y”. However if you wish to try for a little extra credit, you can do data validation on the input for GotAPlayer. But if you do that, make sure it works.

Third Change: Data Validation for the Y/N answer to whether or not they’ve played three games.

You now have a nice way to handle the problem of a user who accidentally answers your question “Has the participant player three games?” with something other than a “Y” or and “N”. When you ask the user if he/she has played three games, you should use a data validation loop to allow only entries of “Y” or “N” …. Be very careful with your logic for that condition! If the user enters something else, display a friendly message and make them answer the question again, and again, and again. Sooner or later they’ll get it right.

Your basic logic from the earlier assignment (which handled one freegumpher) should have been something like:

Get the answer to the “Played three games” question.

If it is no, print an appropriate message.

Otherwise, if it is yes, do the appropriate inputs and calculations.

Otherwise, print an error message (because if u ever get into this “otherwise”, they must not have entered a “y” or an “N)

After adding the data validation loop, the basic logic for one Freegumpher looks sort of like:

Get the answer to the “Played three games” question

As long as they keep entering an invalid response (something other than Y or N)

Display an error message and make them answer again

Once the loop has finished (at which time you must have a Y or an N)

If the answer is No, print an appropriate message.

Otherwise, it is yes, so do the appropriate inputs and calculations.

Note: Once you include the data validation loop, there is no way an answer can be anything other than Y or N once the loop terminates. So when you desk check to see if its N, and you find out that it isn’t, it must be Y. It is unnecessary, and unsophisticated to test to see if it is Y at that point!

Fourth Change:: The customer has asked for one additional piece of information in the output. They want to know the AVERAGE SCORE for all of the freegumphers. Of course, that can and should only include those who have played enough games, since we don’t’ get any scores for those who have not

So the final output for your algorithm will be the average Freegumph score, Be carefull!! This means you need to keep track of the total of all the scores (or all the averages, depending on how you choose to approach the problem) and the number of Freegumphers who had scores. It is, of course possible that no Freegumphers will provide scores on any given run of the program B your program needs to be sure it handles such a case correctly.

Old Program, that goes with this program.

• AdjFact = .7
• NumGames = 3
• Par = 27
• Display “Have you played freegumph before. Please Enter ‘Y/y’ for yes or ‘N/n’ for No”
• Input Games
• If (Games = “Y”) or (Games = “y”) or (Games = “N”) or (Games “n”) Then
• Display “You are to stupid to play freegumph”
• Else
• If (Games = “N”) or (Games = “n”) Then
• Display “You have not played enough games”
• Else
• If (Games = “Y”) or (Games = “y”) Then
• Input Score1
• Input Score2
• Input Score3
• Handicap = (Score1 + Score2 + Score3) / NumGames
• Else
• If Handicap > Par
• Display “Your score is zero”
• Else
• If Handicap <= Par
• Total= Par – Handicap
• Final = Total * AdjFact
• Display “Your score is “ & Final & “.”
• EndIf
• End

3. ### QckrunNew Member

Joined:
Dec 29, 2004
Messages:
6,172
0
Location:
CA
I will offer a PayPal Donation to the person who helps!

4. ### kingtoadOT Supporter

Joined:
Sep 2, 2003
Messages:
55,914
8
Location:
Los Angeles
I've never even heard of "Visual Logic".

5. ### SLEDbuild an idiot proof device and someone else will

Joined:
Sep 20, 2001
Messages:
28,118
0
Location:
AZ, like a bauce!
asking specific questions to obtain help with assignments is allowed. This is a "do my homework" thread, which are not allowed in this forum. Take the time and learn it. Pay attention in class.

Last word.

Joined:
Jan 22, 2001
Messages:
4,603