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

  Write a class player contain attributes for player

write a class player contain attributes for the player name average and team.write three functions to input change and display these attributes.also write a constructor that asks for input initilize all the attributes?

  Program for sentinel address of all zeros and nickname

Explain class called address_t with members for four integers and must read list up to 100 addresses and nicknames terminated by sentinel address of all zeros and nickname.

  Enter codes of one to eight characters along

Consider a program to enter codes of one to eight characters along with an associated telephone number and associated notes. A code can represent a person's name, a person's initials, a place, or anything.

  Write program using while loop to output squares of integers

Write a program that uses while loop to perform the following steps:Output the sum of all the even numbers between firstnum and secondnum inclusive. Output all the numbers and their squares between firstnum and secondnum inclusive.

  Customer ordering mobile app of a pizza house

Application should be adaptive enough to render on multiple devices with various form factors. To make customer experience best advanced capabilities like geo-location, augmented reality and mashups should be used.

  Building airline reservation system

Problem Description The aim of this project is to build airline reservation system. System must give two basic sets of services to an airline: First set of services allows the airline to provision its system.

  Write a checkbook application

I have attached a zip file of what I have completed so far in this checkbook organizer program. I need to edit this program so that the transactions entered into the checkbook application are able to be double clicked and view the details from a s..

  Deploy several visual basic.net applications

Your supervisor has asked you to develop a plan to deploy several Visual Basic.NET applications to users in your company.

  Write program which uses while loops to input two integers

Write the program which uses while loops to perform the following steps: prompt the user to input two integers: firstNum and secondNum.(firstNum must be less than secondNum.

  Design and implement a stringed musical instrument class

Design and implement a Java program that will gather integer numbers and performs some computations on the data entered. The program should use separate methods for inputting the data, calculating the sum, calculating the average, calculating the ..

  Write at least two test cases to check for errors

Write a program that accepts a given number an input from the user and prints prime numbers up to that number.

  Lotteries is that a distinctive sequence

a common misconception about lotteries is that a distinctive sequence, such as 0-0-0-0, is less likely D occur than a random-looking sequence, such as 3-7-5-2. In reality, each number sequence has the ame probability of appearing. It just so happe..

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