Question

In: Computer Science

Goal: To bring together everything you've learned about repetition, relational operators, and input validation and show...

Goal: To bring together everything you've learned about repetition, relational operators, and input validation and show your mastery of these concepts.


You are to write a program that will allow a user to enter as many numbers as they want (one number at a time and all numbers must be 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:

An IPO or Flowchart for the problem.

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.

C Code

Solutions

Expert Solution

Program code:

#include<stdio.h>
int main()
{
    int array[1000],min=1000,max=0,count=0,i,val,ch;
    float sum=0,average;
    while(1)
    {
        printf("Enter a number:");
        scanf("%d",&val);
        if(val>0)
        {
           array[count]=val;
           count++;
        }
        else
            printf("Negative values are not allowed...\n");
        printf("Do you want to continue(1/0):");
        scanf("%d",&ch);
        if(ch==0)
            break;
    }
    for(i=0;i<count;i++)
    {
        if(max<array[i])
            max=array[i];
        if(min>array[i])
            min=array[i];
        sum=sum+array[i];
    }
    average=sum/count;
    printf("\nThe lowest number was:%d",min);
    printf("\nThe highest number was:%d",max);
    printf("\nThe number of values entered was:%d",count);
    printf("\nThe average of numbers was:%f",average);
}


Output:

Testcase-1:

Testcase-2:

Testcase-3:


Related Solutions

Discussion Topic: You've learned a bit about credit cards, but many of us learn about them...
Discussion Topic: You've learned a bit about credit cards, but many of us learn about them the hard way. While sometimes people are forced into misusing credit cards due to circumstances beyond their control , sometimes the new availability of credit causes us to be less than prudent. Without divulging any personal information about anyone, share a story you've heard, know about, or researched (a search on credit card horror stories is usually very fruitful) about someone misusing credit cards...
In the past two weeks you have learned about the relational data model and hopefully had...
In the past two weeks you have learned about the relational data model and hopefully had some practice creating a normalized relational schema through the use of entity/relationship modeling. Based on what you know, please think about various types of software application. Consider what the databases that back these applications might look like. Describe at least one application--whether already existing or hypothetical--for which you believe the relational model would NOT be a good fit. Explain why. Describe another application--already existing...
Select all that is /are true about the financial markets. A.financial markets bring together the buyers...
Select all that is /are true about the financial markets. A.financial markets bring together the buyers and sellers of debt and equity together . B.stocks trading on an organized exchange such as the NYSE are also referred to as listed securities. C.Securities traded between two shareholders happen in the primary market. D.When a firm sells shares to the public this is a primary market transaction E. The OTC market has a central location and is also an auction market. F....
Lesson is about Input validation, throwing exceptions, overriding toString Here is what I am supposed to...
Lesson is about Input validation, throwing exceptions, overriding toString Here is what I am supposed to do in the JAVA Language: Model your code from the Time Class Case Study in Chapter 8 of Java How to Program, Late Objects (11th Edition) by Dietel (except the displayTime method and the toUniversalString method). Use a default constructor. The set method will validate that the hourly employee’s rate of pay is not less than $15.00/hour and not greater than $30.00 and validate...
I need to make a final grade 12 physics presentation about everything that i have learned,...
I need to make a final grade 12 physics presentation about everything that i have learned, it can be anything the question: Describe what you learned in every unit and whether or not you were able to meet those expectations. (E.g. what are some topic(s) in each unit course that you feel you understand well or skills you excelled at?).
1. We learned about each of the following experimental stories in class, which together led to...
1. We learned about each of the following experimental stories in class, which together led to the discovery of cell cycle regulation. For each one, list the model organism used, the major experimental steps that were taken, and the major result that was obtained (the significant piece of cell cycle regulation that was uncovered by the experiment) a. Identification of cyclin b. Identification of cell division cycle (CDC) mutants c. Identification of maturation promoting factor (MPF) 2. How did the...
(From 'The Goal' by Eliyahu M. Goldratt) A) Alex Rogo learned a lot about managing his...
(From 'The Goal' by Eliyahu M. Goldratt) A) Alex Rogo learned a lot about managing his plant on the Boy Scout hiking trip. Give 3 examples of problems he encountered on the hike. Describe how he handled them and what new insights about his plant he received from them. B) For each example you gave in the part A, describe how Alex applied a similar strategy in his plant.
Chose (movie, or TV show) and identify 5-10 different psychological concepts you learned about in this...
Chose (movie, or TV show) and identify 5-10 different psychological concepts you learned about in this class that is demonstrated in your chosen (___). Do not simply summarize the (___); instead, make connections between selected psychological concepts and how they are demonstrated in your chosen (___).
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT