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 haskell program to calculates a balanced partition

Write a program in Haskell which calculates a balanced partition of N items where each item has a value between 0 and K such that the difference b/w the sum of the values of first partition,

  Create an application to run in the amazon ec2 service

In this project you will create an application to run in the Amazon EC2 service and you will also create a client that can run on local machine and access your application.

  Explain the process to develop a web page locally

Explain the process to develop a Web page locally

  Write functions

These 14 questions covers java class, Array, link list , generic class.

  Programming assignment

If the user wants to read the input from a file, then the output will also go into a different file . If the user wants to read the input interactively, then the output will go to the screen .

  Write a prolog program using swi proglog

Write a Prolog program using swi proglog

  Create a custom application using eclipse

Create a custom Application Using Eclipse Android Development

  Create a application using the mvc architecture

create a application using the MVC architecture. No scripting elements are allowed in JSP pages.

  Develops bespoke solutions for the rubber industry

Develops bespoke solutions for the rubber industry

  Design a program that models the worms behavior

Design a program that models the worm's behavior.

  Writing a class

Build a class for a type called Fraction

  Design a program that assigns seats on an airplane

Write a program that allows an instructor to keep a grade book and also design and implement a program that assigns seats on an airplane.

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