Create a small program that uses conditions and loops

Assignment Help Programming Languages
Reference no: EM131056067

Pass Task 3.1: Name Tester

Overview

Control flow enables you to easily add conditions and loops to your programs. In this task you will create a small program that uses conditions and loops to output custom messages to users.

Purpose: Learn to use the control flow statements within a program.

Task: Create a program that tests a user's name and echoes a custom message.

Instructions

Create a small program that will check the user's name and respond with different messages for different people.

1. Download and extract the resources for this task.
2. Open NameTester.pas in Sublime Text.
3. Implement a Main procedure with the following logic:
- It reads a name from the user, and displays back a message.
- Check if the name entered is your name.
- If the name is your name, output the message 'Awesome name!'
- Otherwise output the silly name message

Procedure: Main
----------------
Uses: TerminalUserInput
---------------------------------
Variables:
- name (which stores a String value)
---------------------------------
Steps:
   1: Assign name, the result of calling ReadString with the prompt: 'Please enter your name: '

   2: if name is '-add your name here-' then

   3: Output 'Awesome name!'

   4:else

   5: Output name, ' is a silly name'

4. Open a Terminal window and compile and run your program:

- Change into the directory with your code using the cd command
- Compile your program using fpc -S2 NameTester.pas
- Run your program using ./NameTester

5. One message for everyone isn't that much fun. Enhance your Silly Name Tester so that it has custom messages for at least one other person.

Saying that the name is 'silly' will have a much greater effect if we add lots of 'silly's to the out- put... Add a Output Silly Name procedure to your Name Test program. This will output the person's name and ' is a silly silly' ... with 100 'silly's, then ' name'.

Call this new procedure from main when the name is not your name. The pseudocode for this procedure follows:

Procedure: OutputSillyName
---------------------------------
Parameter:
- name (the silly name String) Local Variables:
- i (an integer, used to count the number of loops)
---------------------------------
Steps:

1: Make i equal 0
2: Output (staying on the same line) name, ' is a'
3: While i is less than 100
4: Output (on the same line) ' silly'
5: Increment i (make i equal i + 1)
6: Output ' name!' (moving to a new line)

Questions:

Assume that age has the value 5. List the actions the computer executes when it runs the fol- lowing code.

WriteLn('Message 0');

if age < 10 then begin
WriteLn('Message 1');
end else begin
WriteLn('Message 2');
end;

WriteLn('Message 3');

Assume that age has the value 11. List the actions the computer executes when it runs the fol- lowing code.

WriteLn('Message 0');

if age < 10 then begin
WriteLn('Message 1');
end else begin
WriteLn('Message 2');
end;

WriteLn('Message 3');

Assume that age has the value 7. List the actions the computer executes when it runs the fol- lowing code.

WriteLn('Message 0');

while age < 10 do begin
WriteLn('Message 1'); age := age + 1;
end;

WriteLn('Message 2');

Assume that age has the value

11. List the actions the computer executes when it runs the fol- lowing code.

WriteLn('Message 0');

while age < 10 do begin
WriteLn('Message 1'); age := age + 1;
end;

WriteLn('Message 2');

Assume that age has the value 8. List the actions the computer executes when it runs the fol- lowing code.

WriteLn('Message 0');

while age < 10 do begin
age := age + 2; WriteLn('Message 1'); age := age - 1;
end;

WriteLn('Message 2');

Reference no: EM131056067

Questions Cloud

Barium hydroxide is reacted with the calcium iodide : Barium hydroxide is reacted with the calcium iodide. Calculate how many mL of .30M Ba(OH)2 needed to react with 250mL of .50M CaI2 (Need to write balanced equation first).
Hydrogen single electron : Hydrogen's single electron can occupy any of the atom's distinct quantum states. Determine the number of distinct quantum states in the following energy levels.
What will it cost to place fencing around the garden : A garden is in the shape of a rectangle 47 feet long and 25 feet wide. If fencing costs $7 a foot, what will it cost to place fencing around the garden
Driving forces that shape the organizational environment : 1.Evaluate the fundamental driving forces that shape the organizational environment of the selected company. Be sure to address the following: competing in a global marketplace, workforce diversity, ethics and morality, and technological innovatio..
Create a small program that uses conditions and loops : Control flow enables you to easily add conditions and loops to your programs. In this task you will create a small program that uses conditions and loops to output custom messages to users.
How many different committees are possible : From 9 names on a ballot, a committee of 3 will be elected to attend a political national convention. How many different committees are possible
What cost calculations did you ?nd most troublesome and why : What cost calculations did you ?nd the most troublesome and why? Develop the budget requirements for a 12-month operation of the District Attorney's proposed Sexual Predator Eradication Program using the given budget development assumptions and data..
Find the probability of selecting : You randomly select one card from a 52-card deck. Find the probability of selecting: P(an ace or a 9)
How many possible meals are there : Solve the problem by applying the Fundamental Counting Principle with two groups of items. Show the set up, then the answer. A restaurant offers a choice of 4 salads, 8 main courses, and 4 desserts. How many possible meals are there

Reviews

Write a Review

Programming Languages Questions & Answers

  Program to assign new value to first element of array

Suppose that the ArrayList of integers named has been declared and initialized. Write single statement which assigns a new value to first element of the ArrayList.

  Top-down recursive descent parser

Write a hand-coded top-down recursive descent parser.

  Explain fundamentals types of scalar-array and hash in perl

Later versions of perl moved beyond fundamentals types of scalar, array, and hash and introduced a reference type. Write down the Perl subroutine, referenceTypeExample.

  Complete the function function has three parameters

Complete the function: func in the following program. This function has three parameters: The first and second parameters are of type: int. The third one is a function that has two parameters of type: int and returns a value of type: int.

  Basics of hypertext markup language

The basics of Hypertext Markup Language and World Wide Web.

  How is active directory implemented?

How is Active Directory implemented?

  List all movie ids and titles that have never been rented

List names of the tables that you have created whose name starts with MM. (Hint: use data dictionary view USER_TABLES).

  Which selection technique do you think is best suited

Which selection technique do you think is best suited for such a program? Why? Do you agree that all control structures are nothing but a form of the ''Go to'' statement? Why or why not? Justify your responses with reasons

  Hubspot: inbound marketing and web 2.0

Hubspot: Inbound Marketing and Web 2.0

  Write a query to confirm that the changes have taken effect

write the SQL command to add a new redo log group with two members

  Generate a salary as a number with two digits

Generate a salary as a number with two digits after the decimal point. The salary for a teacher should be in the range from $40,000 to 70,000.

  Create a program to draw image of archery target

Assume that you have been hired to produce a program which draws the image of the archery target-or, if you prefer commercial applications, a logo for national department store.

Free Assignment Quote

Assured A++ Grade

Get guaranteed satisfaction & time on delivery in every assignment order you paid with us! We ensure premium quality solution document along with free turntin report!

All rights reserved! Copyrights ©2019-2020 ExpertsMind IT Educational Pvt Ltd