Download presentation
Presentation is loading. Please wait.
Published byKerry Mills Modified over 9 years ago
1
Count and add list of numbers From user input and from file
2
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
3
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
4
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
5
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
6
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.
Similar presentations
© 2025 SlidePlayer.com. Inc.
All rights reserved.