This section will ask you questions that you will have to find programming solutions to. There will be more than one way of answering each question, so the answers below are only indicative of what we are looking for. As long as you get the same answers it doesn't matter how you do it. You may be given pseudeocode to help you program the problem.
Write a program to enter batting scores until the number 0 is input. And then output the total and average score.
Answer:
Dim count As Integer
Dim total As Integer
Dim score As Integer
Dim average As Integer
Do
Console.WriteLine("Enter Score: ")
score = Console.ReadLine
total += score
count += 1
Loop Until score = 0
average = total / count
Console.WriteLine("Your total score is: " & total)
Console.WriteLine("Your average score is: " & average)
Console.ReadLine()
Answer alternate (BBC BASIC):
LET count%=0: total=0 score=-1 average=0
WHILE score<>0
INPUT "Enter Score: (Or 0 to terminate entry)";"score
total+= score
count%+= 1
ENDWHILE
LET average = total/count : REM Calculate the average at end.
PRINT "Your total score is :";total
PRINT "Your average score is:"; average.
LET username$=""
LET password$=""
login%=FALSE
uservalid%=FALSE
passvalid%=FALSE
WHILE login%=FALSE
REPEAT
REPEAT
username$="":uservalid%=FALSE
INPUT"Enter Username: ";username$
IF username$<>"" THEN uservalid%=TRUE
UNTIL uservalid%
REM Quick and dirty implementation. Most real password fields would be masked input.
REPEAT
password$="":passvalid%=FALSE
INPUT"Enter Password: ";password$
IF password$<>"" THEN passvalid%=TRUE
UNTIL passvalid%
UNTIL uservalid% AND passvalid%
IF NOT(username$="PSN" AND password$="easy") THEN
PRINT"Not Hacked yet!"
ELSE
PRINT"Hacked!":login%=TRUE
ENDIF
ENDWHILE
Write code to print out a Christmas tree of a user defined size: even rows = *, odd = #. For example for the number 4 it should output:
#
**
###
****
Answer:
DimnumberAsIntegerConsole.WriteLine("Please enter a number: ")number=Console.ReadLineForcount=1TonumberIfcountMod2=0ThenForx=1TocountConsole.Write("*")NextConsole.WriteLine()ElseForx=1TocountConsole.Write("#")NextConsole.WriteLine()EndIfNextConsole.ReadLine()
Alternate Answer (BBC BASIC):
LETnumber%=0INPUT"Please enter rows required: ";number%FORcount%=1TOnumber%IFcount%MOD2=0out$="*"ELSEout$="#"PRINT'; : PRINT a new line.FORx=1TOcount%REMfollowedbytherowPRINT;out$;NEXT:NEXT