Question

C++ Visual Studio 2019 Write a C++ console application that accepts up to 5 numbers from...

C++ Visual Studio 2019

Write a C++ console application that accepts up to 5 numbers from the user. Display all numbers, the highest, the lowest, and the average of the numbers. Ask the user if they want to continue entering another set of numbers.

1) Use proper naming conventions for your variables and functions.
2) Tell the user what the program is all about. Do NOT start the program with “Enter a number”!!
3) Create an array to store the numbers.
4) The user does not have to enter all 5 numbers. They can enter fewer. However, of course, you need at least two numbers to be able to look for the highest and the lowest. Make sure you explain this to the user.
5) Create three functions to perform the following tasks:
a. Calculate the highest number.
b. Calculate the lowest number.
c. Calculate the average.
6) All three functions receive an array and the number of elements, and return a single value.

7) Keep track of the number of the values the user enters. Remember, they do not have to enter all 5 numbers.

Homework Answers

Answer #1

#include<iostream>

using namespace std;


int currentArraySize=0;

int ArrayMax(int *arr)

{

int maxelem=INT_MIN;

for(int i=0;i<currentArraySize;i++)

{

if(arr[i]>maxelem)

maxelem=arr[i];

return maxelem;

}

}

int ArrayMin(int *arr)

{

int minelem=INT_MAX;

for(int i=0;i<currentArraySize;i++)

{

if(arr[i]<minelem)

minelem=arr[i];

return minelem;

}

}

float ArrayAvg(int *arr)

{

float sum=0,avg;

for(int i=0;i<currentArraySize;i++)

{

sum=sum+arr[i];

}

return sum/currentArraySize;

}

int main()

{

int option;

int input[5],elem;

do

{

cout<<"There are currently "<<currentArraySize<<"elements"<<endl;

cout<<"Enter 0 to stop "<<endl;

cout<<"Enter 1 to find max of Elements Entered (min elements=2)"<<endl;

cout<<"Enter 2 to find min of Elements Entered (min elements=2)"<<endl;

cout<<"Enter 3 to find Average of Elements Entered"<<endl;

cout<<"Enter 4 to enter new Elements"<<endl;

cin>>option;

switch(option)

{

case 1:

if(currentArraySize<2)

{

cout<<"Elements less not suffient to 2 enter more elements"<<endl;

}

else

{

cout<<"Maximum element is "<<ArrayMax(input)<<endl;

}

break;

case 2:

if(currentArraySize<2)

{

cout<<"Elements less not suffient to 2 enter more elements"<<endl;

}

else

{

cout<<"Minimum element is "<<ArrayMin(input)<<endl;

}

break;

case 3:

cout<<"Average of Elements is "<<ArrayAvg(input)<<endl;

break;

case 4:

if(currentArraySize ==5)

{

cout<<"Already 5 elements present"<<endl;

}

else

{

cout<<"enter Element"<<endl;

cin>>elem;

input[currentArraySize++]=elem;

}

break;

}

}while(option!=0 );


}

above shows output handles all case copy the code and run on ur machine to check

Thanks happy coding !

Know the answer?
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for?
Ask your own homework help question
Similar Questions
Create a Visual Studio console project named exercise071 containing a main() program that in a single...
Create a Visual Studio console project named exercise071 containing a main() program that in a single statement declares an int array named primes and initializes the 5 entries to the first prime numbers. The primes start at 2 since 1 is not a prime number. Display the array on a single console line beginning with "Primes: " and a blank separating the numbers. A loop is not required.
visual studio VB.Net write a vb.net program to create an array of 15 structures, each structure...
visual studio VB.Net write a vb.net program to create an array of 15 structures, each structure contains the following fields: user name, number of posts, then write a sub to read from the keyboard values into the structures fields and write a function to find and return the average of number of posts for all users and write a sub to print the user name that has zero number of posts.[ number of posts could be from 0 or more]
Write a program in C++ that inputs an unknown number of test scores (assume that there...
Write a program in C++ that inputs an unknown number of test scores (assume that there is a maximum of 150 scores). Ask the user how many scores that they will be entering. The program should have at least 3 functions. Make sure the functions perform the following: Calculate the average score Find the highest score Find the lowest score Sort the list from highest to lowest Output the number of scores, the average, the sorted list, the highest, and...
with C# create a console application that asks the user for two numbers in the range...
with C# create a console application that asks the user for two numbers in the range 0-255 and then divides the first number by the second: Enter a number between 0 and 255: 100 Enter another number between 0 and 255: 8 100 divided by 8 is 12 Enter a number between 0 and 255: apples Enter another number between 0 and 255: bananas FormatException: Input string was not in a correct format.
Questions: 1. (5 marks) Create a VB.NET Console Application that defines a function Smallest and calls...
Questions: 1. Create a VB.NET Console Application that defines a function Smallest and calls this function from the main program. The function Smallest takes three parameters, all of the Integer data type, and returns the value of the smallest among the three parameters. The main program should (1) Prompt a message (using Console.WriteLine) to ask the user to input three integers. (2) Call the built-in function Console.ReadLine() three times to get the user’s input. (3) Convert the user’s input from...
Please use Python 3 4). Write a program that asks the user to enter 10 numbers....
Please use Python 3 4). Write a program that asks the user to enter 10 numbers. The program should store the numbers in a list and then display the following data: • The lowest number in the list • The highest number in the list •The total of the numbers in the list • The average of the numbers in the list   Sample input & output: (Prompt) Enter Number 1: (User enter) 4 (Prompt) Enter Number 2: (User enter) 7...
C+ VISUAL STUDIO.. SHOW OUTPUT PLEASE Write a program that computes the number of possible combinations...
C+ VISUAL STUDIO.. SHOW OUTPUT PLEASE Write a program that computes the number of possible combinations to obtain a successful result of an arbitrary event. The formula for computing the possible combinations is given by: C(n,k)= n! / [k! * (n - k)!] where, n = the number of events k = number of success for that event Use the recursive function factorial explained in the chapter to compute the possible combinations.  The output should be displayed as follows: C( n,...
Write a console application to total a set of numbers indicated and provided by a user,...
Write a console application to total a set of numbers indicated and provided by a user, using a while loop or a do…while loop according to the user’s menu choice as follows: Example Menu 1. To total numbers using a while loop 2. To total numbers using a do...while loop Enter your menu choice: 1 How many numbers do you want to add: 2 Enter a value for number 1: 4 Enter a value for number 2: 5 The total...
(C language) <stdio.h> decisions (else if or switch) Write a program to calculate the average of...
(C language) <stdio.h> decisions (else if or switch) Write a program to calculate the average of the 2 highest numbers entered. Ask the user to enter 3 integers, determine which 2 integers are the 2 highest, and then calculate and display the average of the 2 highest numbers. Format the answer to 2 decimal places. The numbers can be entered in any sequence - lowest to highest, highest to lowest, or completely random. A decision block will be necessary to...
C++ INSTRUCTIONS Problem Specification : Write a program that reads a group of numbers from the...
C++ INSTRUCTIONS Problem Specification : Write a program that reads a group of numbers from the user and places them in an array of type float. Once the numbers are stored in the array, the program should average and print the result. Use pointer notation wherever possible. Program Output (with Input Shown in Bold): Enter number: 2 Enter another (y/n)? y Enter number: 4 Enter another (y/n)? y Enter number: 6 Enter another (y/n)? y Enter number: 8 Enter another...
ADVERTISEMENT
Need Online Homework Help?

Get Answers For Free
Most questions answered within 1 hours.

Ask a Question
ADVERTISEMENT