Free Essay

Cmis 102 Hw3

In:

Submitted By mmcormi
Words 559
Pages 3
Problem definition: Write a program that will calculate and display the average of an unknown number of positive floating point values entered by a user.

A. Problem Analysis – Following the directions in the assignment, clearly write up your problem analysis in this section.
What is the required output?
The calculated average of all the numbers the user input.

What is the required input?
The numbers that are greater than or equal to 0 that the user wants to find the average of. A number less than 0 (any negative number) to tell the program to end the input module and start the process module.

How will you obtain the output from the given input?

number – (float) the number(s) the user input that they want to find the average of. count – (integer) the total number of numbers the user inputs that are greater than or equal to 0 sum – (float) the total of all the numbers the user inputs. average = (float) the average of all the numbers the user inputs.

Formula –

Set sum = 0.0
Set count = 0
While number >= 0 then
Set sum = sum + number
Set count = count + 1
End While
Set number = sum / count

Sample Calculation

If user inputs 30, 20, 50, and -2
Input 30
While number >=0 then 30>=0 is true go to enter while loop
Set sum = sum + number 0 + 30 = 30
Set count = count + 1 0 + 1 = 1
Input 20
While number >=0 then 20>=0 is true continue in while loop
Set sum = sum + number 30 + 20 = 50
Set count = count + 1 1 + 1 = 2
Input 50
While number >= 0 then 50 >= 0 is true continue in while loop
Set sum = sum + number 50+50=100
Set count = count + 1 2 +1 = 3
Input -2
While number is >= 0 then is – 2 >= 0 is false end while loop
Set number = sum / count 100/3 = 33.3333333

B. Program Design – Following the directions in the assignment, clearly write up your problem design in this section and comment your pseudocode.
/*
Number Grade to Letter Grade
A program that prompts and gets the numbers from the user, calculates the average of the number given, and then outputs the average of those numbers to the user.
Written by. M. Cormier
Date: 6/21/2015
*/
Main Module

Declare number, sum, average as float
Declare count as interger
Set count = 0
Set sum = 0.0
Call input_data module
Call process module
Call output module

End Program

// Input Module
// Prompts and gets the numbers the user wants to average
//
input_data module

Write "Which numbers do you want the average of?"
Input number
While number >= 0 set sum = sum + number set count = count + 1
Input number
End While // While number >= 0

End input_data module

// Process module
// Calculates the average of the numbers the user input
//
process module

Set average = sum / count

End process module

// Output Module
// Outputs the average number of all the numbers the user input.
//
output module

Write “The average is” average “!”

End output module

C. Test Data – Following the directions in the assignment, include your test data and expected results in this section.
Table 1. Include your test data table here
Input Data Expect Output
40.2, 80.3, 54.1, 30.4, -4.2 51.25
100000, 123000, 413000, -512892 212000
0.75, 0.927, 0.123, 0.664, 0.995, -0.122 0.6918

Similar Documents