Preview

Unit 7 Assignment 1

Good Essays
Open Document
Open Document
749 Words
Grammar
Grammar
Plagiarism
Plagiarism
Writing
Writing
Score
Score
Unit 7 Assignment 1
Unit 7 Assignment 1
Steven Rogusta
ITT Technical Institute
PT1420 Intro to Programming
Misty Kitzul
November 1, 2014
Unit 1 Assignment 1
Short Answer
Why should you indent the statements in the body of a loop? It visually set them apart from the surrounding code, this makes your program easier to read and debug.
Describe the difference between pretest loops and posttest loops? Pretest loop or do while loop tests its condition before performing iteration whereas a posttest loop or do until loop executes one or more statements and then a condition is tested.
What is condition-controlled loop? Condition-controlled loop uses a true/ false condition to control the number of times that it repeats.
What is a count-controlled loop? Count-controlled loop repeats specific number of times.
What are three actions do count-controlled loop typically performed using the counter variable? Initialization, Test, Increment Algorithm Workbench
Design a While loop that lets the user enter a number. The number should be multiplied by 10, and the result stored in a variable named product. The loop should iterate as long as product contains a value less than 100.
//Declare product = 0
Do
Display “Enter a number.”
Input number
Product = number x 10
While product < = 100
Design a Do-While loop that asks the user to enter two numbers. The numbers should be added and the sum displayed. The loop should ask the user if he or she wishes to perform the operation again. If so, the loop should repeat, otherwise it should terminate.
Declare 1num as RealDeclare 2num as RealDeclare sumNum as realDoDisplay “What is your first number”Input 1numDisplay “What is your second number”Input 2numsumNum = 1num+2numDisplay “sum num”
Convert the While loop in the following code to Do-While loops:
Declare Integer x = 1
While x > 0 Display “Enter a number. “ Input x
End While
Declare x as Integer = 1
Do
Display “Enter a number.”
Input x
If x ! = 0 then

You May Also Find These Documents Helpful

  • Satisfactory Essays

    Unit 7 Assignment 1

    • 609 Words
    • 3 Pages

    Switched circuit- A circuit created by the phone company in reaction to signaling (the user tapping telephone keys or a modem sending in the same digits), with the telco tearing down the circuit when the user is finished.…

    • 609 Words
    • 3 Pages
    Satisfactory Essays
  • Satisfactory Essays

    cout << num1 << " + " << num2 << " = " << num1+num2;…

    • 426 Words
    • 2 Pages
    Satisfactory Essays
  • Powerful Essays

    POW 9 IMP3

    • 1192 Words
    • 5 Pages

    Create 2 formulas, one that will calculate the last number in terms of the first number and a constant increase in rate as well as the total amount of numbers. The second formula will add ass of the resulting numbers from the first formula together after the last number is calculated.…

    • 1192 Words
    • 5 Pages
    Powerful Essays
  • Satisfactory Essays

    a. Adds 2 to a and stores the result in b// Ans.)B = 2 + A…

    • 453 Words
    • 3 Pages
    Satisfactory Essays
  • Good Essays

    ops335 lab 2 firewall

    • 695 Words
    • 4 Pages

    4. Enter the list price of the book and include a dollar sign in the prompt. Make the list price a decimal data type or test to ensure that the user entered a numerical value.…

    • 695 Words
    • 4 Pages
    Good Essays
  • Satisfactory Essays

    unit 7 assignment 1

    • 431 Words
    • 2 Pages

    3. What is a condition-controlled loop? A condition-controlled loop uses a true/false condition to control the number of times it repeats.…

    • 431 Words
    • 2 Pages
    Satisfactory Essays
  • Satisfactory Essays

    Unit 7 Assignment 1

    • 261 Words
    • 2 Pages

    2. A pretest loop is a loop tests the conditions before performing the iteration. A posttest loop performs the iteration then test the condition.…

    • 261 Words
    • 2 Pages
    Satisfactory Essays
  • Satisfactory Essays

    Chapter 8 Problem 1

    • 175 Words
    • 2 Pages

    Analysis: The problems required output is the students name with scores from three tests. Each student and scores shall be listed on separate lines. The input variables needed for this program include Test1, Test2, Test3, and Student.…

    • 175 Words
    • 2 Pages
    Satisfactory Essays
  • Satisfactory Essays

    Chid Abuse

    • 829 Words
    • 4 Pages

    | Group the Main St. and Franklin Ave. worksheet tabs. With both worksheets selected, click in cell F6 and insert a function that will total…

    • 829 Words
    • 4 Pages
    Satisfactory Essays
  • Good Essays

    Programing Problems

    • 721 Words
    • 3 Pages

    End User Input Module Unit Weight Module UnitWeight =ItemWeight*16 End Unit Weight Module Unit Price Module UnitPrice=ItemPrice/UnitWeight End Unit Price Module Total Price Module TotalPrice=UnitWeight*UnitPrice End Total Price Module…

    • 721 Words
    • 3 Pages
    Good Essays
  • Satisfactory Essays

    Code for an Infinite Loop

    • 457 Words
    • 4 Pages

    An accumulator is used to keep a running total of numbers. In a loop, a value is usually added to the current value of the accumulator. If it is not properly initialized, it will not contain the correct total.…

    • 457 Words
    • 4 Pages
    Satisfactory Essays
  • Good Essays

    Repetition control structure is also known as looping or iteration control structure. .Repetition is the act of repeating steps in a certain process. It consists of a branching backwards away from the normal sequence of steps towards an earlier step. The branching decision is based on a relationship between the values of known data (condition) at the time that the branching test is performed. The condition is usually based on the value of a single variable (control variable). The steps to be repeated are referred to as the loop body. Each execution of the steps is referred to as a pass or iteration. The step where the body starts is called as the loop entrance and the step where the test branches back fails is known as the loop exit, it causes the repetition to stop.…

    • 530 Words
    • 3 Pages
    Good Essays
  • Satisfactory Essays

    MIPS assembly language

    • 610 Words
    • 3 Pages

    The following is a MIPS assembly language implementation of the for-loop assuming that $3, $4, and $5 are used to store i, j, and k, respectively.…

    • 610 Words
    • 3 Pages
    Satisfactory Essays
  • Good Essays

    1.2 Write a Java program to display default value of all primitive data types of…

    • 2916 Words
    • 12 Pages
    Good Essays
  • Satisfactory Essays

    Phuck U

    • 308 Words
    • 2 Pages

    Assignment Module: C Programming Language Learning Units: a) Introduction to C language b) Operators and basic types c) Control flow 1. Write a Program to input three positive integers representing the sides of a triangle and determine whether they form a valid triangle or not. 2. To round off a floating point number to the nearest integer, one adds 0.5 to the number and truncates it to an integer. Using this knowledge, try to figure out how to round a floating point number to the nearest tenth, hundredth, etc and implement the same. 3. Write a program that repeatedly ask the user to input a negative or positive number, and then echoes it. When the value 0 is entered, the program should terminate. It also keeps a count of how many of the numbers are positive and how many are negative. The program should print out these two totals immediately before terminating. 4. Write a program to which accepts a number n, and then finds the sum of the integers from 1 to 2, then from 1 to 3, then 1 to 4 and so forth until it displays the sum of the integers from 1 to n. For example, if the input is 5, the output will be 1 3 6 10 15 5 Write a program to implement the Russian Peasant Problem for multiplying two positive numbers using while or do…while loop. Russian Peasant problem is a method of multiplying two numbers together, using only division by 2, multiplication by 2 and addition. For example, if the numbers are 17 and 19are to be multiplied together, they are put at the head of two columns: The first number is divided by 2 and the second number is multiplied by 2. This process is continued until the number on the left reduces to 1.…

    • 308 Words
    • 2 Pages
    Satisfactory Essays