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

  List all web based programming languages

1. List all web based programming languages 2. What does server side scripting mean.? 3. What is front end scripting.

  Explain book constructor to accept and initialize data

Create and execute the class called Book which contains instance data for title, author, publisher, and copyright date. Explain the Book constructor to accept and initialize this data.

  Create useful and well-designed programs

Create useful and well-designed programs that use subroutines, functions, menus, dialog boxes, and other related form objects to solve practical business problems.

  Write software application development coding practices

Use the Library and other resources to write a software application development coding practices guide. Your guide should include recommendations

  Application should calculate and display the order amounts

Make sure the number of units for each package is numeric, and is not negative.

  Assignment on the two-dimensional array sales

Use a two-dimensional array to solve the following problem: A company has four salespeople (1 to 4) who sell five different products (1 to 5). Once a day, each salesperson passesin a slip for each type of product sold. Each slip contains the follo..

  Utilizing the step-by-step mrp calculation process students

utilizing the step-by-step mrp calculation process students will solve the following mrp problem given product a is an

  Prepare function for one integer parameter-returns integer

Prepare the C++ function which needs one integer parameter and returns the integer value. Function will double value passed to it and return doubled value.

  Program to processes the test data

Write a program that processes the test data. The output should be the student's ID, followed by the answers, followed by the test score, and followed by the test grade.

  Write a program to print average grade of student

Write a program that read the grades.txt file and then prints the average grade of male and female students and the number of passed students by using the functions.

  Create an instance of the person class

Create an instance of the Person class

  Implement a program that prompts the user for an integer

Implement a program that prompts the user for an integer n and prints the nth Fibonacci number, using the above algorithm.

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