Download as pdf or txt
Download as pdf or txt
You are on page 1of 4

Assignment 7

You are to write a program that will allow a user to enter infinite numbers (one number at a
time and all numbers are greater than zero). You must have a way for the user to stop entering
values. Once the user stops, you will immediately display the following:
The lowest number was:
The highest number was:
The number of values entered was:
The average of the numbers was:
1. IPO or Flowchart for the problem.
Input Process Output
Random numbers Write a program that will The lowest number was:
allow a user to enter
infinite numbers (one The highest number was:
number at a time and all
numbers are greater than The number of values
zero). Have a way for the entered was:
user to stop entering
values. The average of the
Once the user stops, numbers was:
display the following:
- The lowest number was:
- The highest number was:
- The number of values
entered was:
- The average of the
numbers was:

2. A test case sheet that shows 3 sets of input data, and the expected results of running the
program for each set of input data:

TEST CASE 1:

Grades Entered: Expected Results


67
77
4
-1
The lowest number was: 4

The highest number was: 77

The number of values entered was: 3

The average of the numbers was: 49.00

This study source was downloaded by 100000831727298 from CourseHero.com on 04-03-2022 09:34:40 GMT -05:00

https://www.coursehero.com/file/58907510/-Assignment-7docx/
TEST CASE 2:

Grades Entered: Expected Results


109
59
455
35
18
-1
The lowest number was: 18

The highest number was: 455

The number of values entered was: 5

The average of the numbers was: 135.00


TEST CASE 3:

Grades Entered: Expected Results


99
670
900
80
65
20
-1
The lowest number was: 20

The highest number was: 900

The number of values entered was: 6

The average of the numbers was: 305.00

3. The code (with appropriate comments) that solves the problem :

/*Write a program that will allow a user to enter infinite numbers (one number at
a time
and all numbers are greater than zero). Have a way for the user to stop entering
values.
Once the user stops, display the following:
- The lowest number was:
- The highest number was:
- The number of values entered was:
- The average of the numbers was:*/

#include <stdio.h>
#include <stdlib.h>

int main(void)
{
//Declared variables
int number, lowNum = 0, highNum = 0, sum = 0, totalValues = 0;
double average;

//Asks user to input numbers


printf("Enter a number greater than 0 (press -1 to stop): ");
scanf_s("%i", &number);
This study source was downloaded by 100000831727298 from CourseHero.com on 04-03-2022 09:34:40 GMT -05:00

https://www.coursehero.com/file/58907510/-Assignment-7docx/
while (number != -1) //As the user inputs numbers, he/she can stop by
entering -1
{
if (number > highNum)
{ /*If the variable number is greater than the variable
highNum, then the highest number will be displayed*/
highNum = number;
}

else if (number < highNum)


{
/*If the variable number is lower than the variable
highNum, then the lowest number will be displayed*/
lowNum = number;
}
totalValues = totalValues + 1; /* totalValues = 0 , SO it will add by
1 because it will show how many values were entered by the
user*/

sum = sum + number; /*The numbers that were entered by the user and
added together to get a total sum*/

printf("Enter a number greater than 0 (press -1 to stop): ");


scanf_s("%i", &number);

average = sum / totalValues; /* The total sum of the numbers divided


by the number of values entered*/

printf("The lowest number was: %i \n", lowNum); //The lowest number will be
displayed
printf("The highest number was: %i \n", highNum); //The highest number will
be displayed
printf("The number of values entered was: %i \n",totalValues); //Shows how
many values were
entered
printf("The average of the numbers was: %.2lf \n", average); //Displays the
average of the
numbers

system("pause");
return 0;
}

4. Screen shots of running the program 3 different times. Use each of the test cases that
you have created.

This study source was downloaded by 100000831727298 from CourseHero.com on 04-03-2022 09:34:40 GMT -05:00

https://www.coursehero.com/file/58907510/-Assignment-7docx/
This study source was downloaded by 100000831727298 from CourseHero.com on 04-03-2022 09:34:40 GMT -05:00

https://www.coursehero.com/file/58907510/-Assignment-7docx/
Powered by TCPDF (www.tcpdf.org)

You might also like