Count and add list of numbers From user input and from file.

Slides:



Advertisements
Similar presentations
Exercise (1).
Advertisements

Excel and Visual Basic. Outline Data exchange between Excel and Visual Basic. Programming VB in Excel.
1 9/29/06CS150 Introduction to Computer Science 1 Loops Section Page 255.
The UNIVERSITY of NORTH CAROLINA at CHAPEL HILL Adrian Ilie COMP 14 Introduction to Programming Adrian Ilie July 5, 2005.
CS107 Introduction to Computer Science Loops. Instructions Pseudocode Assign values to variables using basic arithmetic operations x = 3 y = x/10 z =
BACS 287 Programming Logic 3. BACS 287 Iteration Constructs Iteration constructs are used when you want to execute a segment of code several times. In.
Loops Counting down from N to 1 in assembly we used JUMP statements to repeat previous instructions thus looping READ LOOP: WRITE SUB decrement JPOSLOOP.
1 9/29/06CS150 Introduction to Computer Science 1 Loops Section Page 255.
CS150 Introduction to Computer Science 1
1 Lab Session-3 CSIT221 Spring 2003 b Group Worksheet 3 Exercise (Demo Required) b No new lab demo will be assigned to allow you to focus on HW#1.
Designing Algorithms Csci 107 Lecture 3. Designing algorithms Last time –Pseudocode –Algorithm: computing the sum 1+2+…+n –Gauss formula for 1+2+…+n Today.
Flowcharts Remember that a solution to a problem is called an algorithm. Algorithms are often a series of steps required to solve the problem. A flowchart.
18 File handling1June File handling CE : Fundamental Programming Techniques.
Lecture 12 Another loop for repetition The while loop construct © 2007 Daniel Valentine. All rights reserved. Published by Elsevier.
1 10/9/06CS150 Introduction to Computer Science 1 for Loops.
COMP 14 Introduction to Programming Miguel A. Otaduy May 20, 2004.
Chapter seven review. What is the output of: Private Sub cmdButton_Click() Dim i As Integer, a(1 To 4) As integer Open "DATA.TXT" For Input As #1 For.
Computing Sums and Averages 04/17/15. Totaling Up a List Write a program to input a list of four numbers and output the total.
Chapter 6 - Visual Basic Schneider
Arrays. What is the output of: Private Sub cmdButton_Click() Dim i As Integer, a(1 To 4) As integer Open "DATA.TXT" For Input As #1 For i = 1 To 4 Input.
1 Chapter 6 Repetition. 2 Outline & Objectives Loop Structure Loop Structure Elements of a Loop Structure Elements of a Loop Structure Processing Lists.
COMP 110 Introduction to Programming Mr. Joshua Stough September 24, 2007.
Multiplying and Dividing Integers 1.9. Rules: Multiply or divide SAME sign the product or quotient is POSITIVE Examples: 1.) -2∙ (-22)= 2.) -45÷ (-9)=
ADDING INTEGERS Positive + Positive = Positive Positive + Positive = Positive ( +3) + (+2) = +5 ( +3) + (+2) = +5 When a number is positive, you do not.
CS Class 07 Topics –  When software goes wrong  Count controlled loops  Sentential controlled loops  putting it all together Announcements.
Building Java Programs Chapter 5 Program Logic and Indefinite Loops Copyright (c) Pearson All rights reserved.
Repetition Statements Repeating an Action A specified number of times While a Condition is True Until a Condition is True.
Practice and Evaluation. Practice Develop a java class called: SumCalculator.java which computes a sum of all integer from 1 to 100 and displays the result.
More While Loop Examples CS303E: Elements of Computers and Programming.
Introduction to C Programming CE Lecture 4 Further Control Structures in C.
Practice with Lists and Strings CS303E: Elements of Computers and Programming.
Visual Basic.net Loops. Used to do multiple executions of the same block of code Do while loops Do until loops For next loops.
Input and Output. Announcements  Exam Next Wednesday –Next Monday: Review session.  Invited talk: –7:30 PM,Tuesday, Oct 28th. –Prof. Katherine Socha.
 Wednesday, 9/18/02, Slide #1 CS106 Introduction to CS1 Wednesday, 9/18/02  QUESTIONS?? HW #1 due today at 5!!  Today: Loops, and two new data types.
1 Three C++ Looping Statements Chapter 7 CSIS 10A.
Ch. 10 For Statement Dr. Bernard Chen Ph.D. University of Central Arkansas Spring 2012.
Lecture 5: Stopping with a Sentinel. Using a Sentinel Problem Develop a class-averaging program that will process an arbitrary number of grades each time.
Exercise 1 Introduction to C# CIS Code the C# program to prompt the user to key in 12 integer values from the keyboard. If a value containing.
Loops and Simple Functions CS303E: Elements of Computers and Programming.
Think Possibility 1 Iterative Constructs ITERATION / LOOPS C provides three loop structures: the for-loop, the while-loop, and the do-while-loop. Each.
Chapter 61 Example : For … To… Step For index = 0 To n Step s lstValues.Items.Add(index) Next Control variable Start value Stop value Amount to add to.
Think First, Code Second Understand the problem Work out step by step procedure for solving the problem (algorithm) top down design and stepwise refinement.
مقدمة في البرمجة Lecture 7. Write VB.net project using the for loop to calculate : 1- the sum of numbers from 1 to (A) numbers. 2- the sum of Odd numbers.
1 Chapter 8: File Processing Part 1. 2 Outline  Why Files?  Opening Files  Reading from Files  Writing to Files  Working with Multiple Files  Closing.
CPSC 233 Tutorial 5 February 2 th /3 th, Java Loop Statements A portion of a program that repeats a statement or a group of statements is called.
For loop. Exercise 1 Write a program to have the user input three (3) numbers: (f)rom, (t)o, and (i)ncrement. Count from f to t in increments of i, inclusive.
Chapter 6 - Visual Basic Schneider1 Chapter 6 Repetition.
Exercise 2 : Using for loop Repetition (loop) (1)control variable initialization (2)Test Conditon (3)Modification of control variable value order : (1)
Loops Review. How to generate random numbers Math.random() will return a random decimal value in the form of a double. double num1 = Math.random(); num1.
Looping Examples I.
while Repetition Structure
for Repetition Structures
While Loops in Python.
Chapter 6 – Repetition 6.1 Do Loops 6.2 For...Next Loops
Logical Operators and While Loops
Chapter 4 LOOPS © Bobby Hoggard, Department of Computer Science, East Carolina University / These slides may not be used or duplicated without permission.
Lesson #5 Repetition and Loops.
More Loops.
More Loops.
For -G7 programing language Teacher / Shamsa Hassan Alhassouni.
Chapter 8 The Loops By: Mr. Baha Hanene.
Chapter (3) - Looping Questions.
Suppose I want to add all the even integers from 1 to 100 (inclusive)
CS150 Introduction to Computer Science 1
Logical Operators and While Loops
Repetition (While Loop) LAB 9
GCSE Computing:: While Loops
CSCE 206 Lab Structured Programming in C
Introduction to Algorithms - 2
Introduction to Algorithms - 2
Presentation transcript:

Count and add list of numbers From user input and from file

Count: From user input criteria to stop: reading negative number Dim Count as integer, Num as integer Count=0 Num=val(inputbox(“ Enter a number: “)) Do while (Num>=0) Count=Count+1 Num=val(inputbox(“ Enter a number: “)) Loop Print “The total numbers read is: “ & Count

Add: From user input criteria to stop: reading negative number Dim Sum as integer, Num as integer Sum=0 Num=val(inputbox(“ Enter a number: “)) Do while (Num>0) Sum=Sum+Num Num=val(inputbox(“ Enter a number: “)) Loop Print “The sum of the numbers read is: “ & Sum

Count: From file (note: counts all numbers in the file) Dim Count as integer, Num as integer Open “data.txt” For Input As #1 Count=0 Do while Not EOF(1) Input #1, Num Count=Count+1 Loop Print “The total numbers read is: “ & Count

Add: From file (note: adds all numbers in the file) Dim Sum as integer, Num as integer Open “data.txt” For Input As #1 Sum=0 Do while Not EOF(1) Input #1, Num Sum=Sum+Num Loop Print “The sum of the numbers read is: “ & Sum

Exercises: –Write a code to find the average for a list of numbers for the previous two case: Read from user input Read from file –Write a code to find the number of the odd and even numbers in a list of numbers for the same two cases.