Question

This assignment is mainly to practice Iteration ( we review this week) and Selection programming structures....

This assignment is mainly to practice Iteration ( we review this week) and Selection programming structures. That is a FOR loop and IF ... THEN ... ELSEIF ... ELSE ... END IF structures.

Open a blank file (use Word or a text editor). Type your name and CS 3 in the beginning of the file.
Save the file as yourlastname-firstname-ProgIteration.docx or save the file as yourlastname-firstname-ProgIteration.txt. Preferably in CS 3 folder that you already created other assignments.
What is the output of the following code, what values of I and HowMuch will be displayed.

DIM i AS INTEGER

DIM HowMuch AS INTEGER

HowMuch = 0

FOR i = 1 TO 10

IF i < 5 THEN

HowMuch = HowMuch + 1

ELSEIF i = 5 THEN

HowMuch = HowMuch - 5

ELSE

HowMuch = HowMuch + 3

END IF

PRINT i, HowMuch

NEXT i

PRINT HowMuch

To receive credit for this assignment, submit yourlastname-firstname-ProgIteration.docx or yourlastname-firstname-ProgIteration.txt in this Assignment. Only ONE file, please.
0 0
Add a comment Improve this question Transcribed image text
Answer #1

The output of the following program will be

1 1
2 2
3 3
4 4
5 -1
6 2
7 5
8 8
9 11
10 14
14

The step by step explanation is as follows:

Initially we have defined HowMuch to 0, and then we are iterating i from 1 to 10.

When i is 1, the first if loop is executed, so 1 is added to Howmuch, so Howmuch will be 1 and the value of i and HowMuch is printed.

When i is 2, the first if loop is executed, so 1 is added to Howmuch, so Howmuch will be 2 and the value of i and HowMuch is printed.

When i is 3, the first if loop is executed, so 1 is added to Howmuch, so Howmuch will be 3 and the value of i and HowMuch is printed.

When i is 4, the first if loop is executed, so 1 is added to Howmuch, so Howmuch will be 4 and the value of i and HowMuch is printed.

When i is 5, the else if loop is executed, so 5 is subtracted from Howmuch, so Howmuch will be -1 and the value of i and HowMuch is printed.

When i is 6, the first if loop is executed, so 3 is added to Howmuch, so Howmuch will be 2 and the value of i and HowMuch is printed.

When i is 7, the first if loop is executed, so 3 is added to Howmuch, so Howmuch will be 5 and the value of i and HowMuch is printed.

When i is 8, the first if loop is executed, so 3 is added to Howmuch, so Howmuch will be 8 and the value of i and HowMuch is printed.

When i is 9 the first if loop is executed, so 3 is added to Howmuch, so Howmuch will be 11 and the value of i and HowMuch is printed.

When i is 10, the first if loop is executed, so 3 is added to Howmuch, so Howmuch will be 14 and the value of i and HowMuch is printed.

and after the for loop is completed, the value of HowMuch is printed. so the final printed value is 14.

Add a comment
Know the answer?
Add Answer to:
This assignment is mainly to practice Iteration ( we review this week) and Selection programming structures....
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • This assignment is mainly to practice Selection programming structure. That is IF ... THEN ... ELSE...

    This assignment is mainly to practice Selection programming structure. That is IF ... THEN ... ELSE ... END IF and  IF ... THEN ... ELSEIF ... ELSEIF .... END IF Open a blank Word or Text file, save this file as: docx or yourlastname_firstname_ProgrammingSelection.txt. Then type the answer to the following questions: What is the output of the following codes, consider each case indecently: Case 1. Assume i = 1 and HowMuch = 0 IF i < 5 THEN     HowMuch...

  • Your mission in this programming assignment is to create a Python program that will take an...

    Your mission in this programming assignment is to create a Python program that will take an input file, determine if the contents of the file contain email addresses and/or phone numbers, create an output file with any found email addresses and phone numbers, and then create an archive with the output file as its contents.   Tasks Your program is to accomplish the following: ‐ Welcome the user to the program ‐ Prompt for and get an input filename, a .txt...

  • Programming Assignment 6: A Python Class, Attributes, Methods, and Objects Obiectives .Be able to...

    I need some help with programming this assignment. Programming Assignment 6: A Python Class, Attributes, Methods, and Objects Obiectives .Be able to write a Python class Be able to define class attributes Be able to define class methods .Be able to process input from a text file .Be able to write an application using objects The goal of this programming assignment is to develop a simple image processing application. The application will import a class that creates image objects with...

  • Programming Assignment #2 (Arrays) I. The Assignment This assignment is to take your Garage class from...

    Programming Assignment #2 (Arrays) I. The Assignment This assignment is to take your Garage class from the previous assignment and modify it so that it uses an array of Car objects as the principal data structure instead of an ArrayList-of-Car. This is an example of the OOP principle of information hiding as your Car and test classes will not have to be modified at all. Unless you broke encapsulationon the previous assignment, that is   II. Specifications Specifications for all 3...

  • Data Structures and Algorithm Analysis – Cop 3530 Module 3 – Programming Assignment This assignment will...

    Data Structures and Algorithm Analysis – Cop 3530 Module 3 – Programming Assignment This assignment will access your skills using C++ strings and dynamic arrays. After completing this assignment you will be able to do the following: (1) allocate memory dynamically, (2) implement a default constructor, (3) insert and remove an item from an unsorted dynamic array of strings, (4) use the string class member functions, (5) implement a copy constructor, (6) overload the assignment operator, (7) overload the insertion...

  • Python Programming Chapter 5 Programming Exercise Dinner Selection Program (60 points total) Pseudocode (10 points) As...

    Python Programming Chapter 5 Programming Exercise Dinner Selection Program (60 points total) Pseudocode (10 points) As the family cook, you know that the toughest question of the day is "What's for dinner?" You For decide to write a program to help you do days of meal planning for the entree, side and dessert. You will need to use random numbers and functions to complete the project. What's Dinner? • • • Start with a pseudocode (10 points). Write the pseudocode...

  • Overview These exercises will allow you to have some practice with basic Java file Input/Output. In...

    Overview These exercises will allow you to have some practice with basic Java file Input/Output. In addition, you will also have an opportunity to have more practice with methods and arrays.   Objectives Practice with programming fundamentals Variables - Declaration and Assignment Primitive types Arithmetic Expressions Simple keyboard input and text display output Branching - if-elseif-else syntax Loops - simple while loops, nested while loops Methods - functions and procedures ArrayLists - collections of variables File I/O Works towards the following...

  • For this set of Review Questions, we will create and use a database for the Wedgewood...

    For this set of Review Questions, we will create and use a database for the Wedgewood Pacific Corporation (WPC) that is similar to the Microsoft Access database we created and used in Chapters 1 and 2. Founded in 1957 in Seattle, Washington, WPC has grown into an internationally recognized organization. The company is located in two buildings. One building houses the Administration, Accounting, Finance, and Human Resources departments, and the second houses the Production, Marketing, and Information Systems departments. The...

  • As we continue with our study of programming fundamentals, here is a short extra credit programming...

    As we continue with our study of programming fundamentals, here is a short extra credit programming challenge involving selection control structures. To be specific, the program specifications below and the algorithm you develop and write will involve the set-up and use of either nested if-else statements and/or switch statements. Choose one of the following programming challenges below for this algorithm workbench extra credit programming challenge… ------------------------------------------------------------------------------------------- Finding median Use selection control structures to write a C++ program that determines the...

  • JAVA project PLEASE complete/ create project with comments in the programming explaining everything Text file Year...

    JAVA project PLEASE complete/ create project with comments in the programming explaining everything Text file Year of storm/ Name of storm/ mmdd storm started/ mmdd storm ended/ magnitude of storm/ //made up data 2004/Ali/1212/1219/1 2003/Bob/1123/1222/3 1980/Sarah/0123/0312/0 1956/Michael/1211/1223/4 1988/Ryan/0926/1019/ 1976/Tim/0318/1010/0 2006/Ronald/0919/1012/2 1996/Mona/0707/0723/1 2000/Kim/0101/0201/1 2001/Jim/1101/1201/3 Text file Class storm{ private String nameStorm; private int yearStorm; private int startStorm; private int endStorm; private int magStorm; public storm(String name, int year, int start, int end, int mag){ nameStorm = name; yearStorm = year; startStorm...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT