Question

In: Computer Science

First, write a program to loop asking for a number from the user until the user...

First, write a program to loop asking for a number from the user until the user inputs a zero or until the user has input 50 numbers. Store each value in an array except the values that are divisible by 5 and display all stored values. Determine how many of the values stored in the array were divisible by 10 and display result.

Next, write a function getMinMax that accepts an array of floats and the size of the array, determines the minimum and maximum values in the array and displays the result. It returns the range. Range = max – min.

C++ Coding Please. Thank you!

Solutions

Expert Solution

Code:

#include <iostream>

using namespace std;
float getMinMax(float a[], int size) //Defining getMinMax function
{
float min = a[0], max = a[0]; //Initializing min, max variables
int i=0;
//Finding min, max values from array
for(i=0;i<size;i++)
{
if(a[i]>max)
{
max = a[i];
}
if(a[i]<min)
{
min = a[i];
}
}
//Returning range
return (max-min);
}
int main()
{
int i=0,j=0,count=0,n=0;float a[50];
//We use for loop to loop statements upto 50 times.
for(i=0;i<50;i++)
{
//Taking user input
cout<<"Enter Number "<<i+1<<" (or Enter 0 To Exit): ";
cin>>n;
//If user enter 0, we break the loop
if(n==0)
{
break;
}
//Assigning number to array if divisible by 5
if(n%5==0)
{
a[j]=n;
j++;
}
//Incrementing count if number divisible by 10
if(n%10==0)
{
count++;
}
}
//Printing count value
cout<<"Numbers Divisible By 10: "<<count<<endl;
//Calling getMinMax to print range of array a[]
cout<<"Range: "<<getMinMax(a,j)<<endl;
return 0;
}

Sample Output:


Related Solutions

Write a C++ program that keeps asking user to enter a positive integer number until a...
Write a C++ program that keeps asking user to enter a positive integer number until a sentinel value (999) is entered. Then for each positive number entered by the user, find out how many digits it consists. (Hint: divide a number by 10 will remove one digit from the number. You can count how many divisions it needs to bring the number to 0.) An example of executing such a program is shown below. Note that the user input is...
What it Looks Like to the User The program will loop, asking the user for a...
What it Looks Like to the User The program will loop, asking the user for a bet amount from 0 to 100 (assume dollars, you can use ints or longs). If the user types a 0 that means she wants to quit. Otherwise, accept the amount as their bet and simulate a slot machine pull. Your program will print out a line that looks like a slot machine result containing three strings. Some examples are:  BAR 7 BAR, 7 7 cherries,...
1. Write a program that keeps asking the user for a password until they correctly name...
1. Write a program that keeps asking the user for a password until they correctly name it. Once they correctly enter the password, the program congratulates the user and tells them how many guesses it took. Be sure to be grammatically correct with the guess/guesses output. Call the program LastNamePassword. Example (user input in italics) What is the password? monkeys Incorrect. Guess again. dishwasher Incorrect. Guess again. aardvark Correct! You got the password, and it took you 3 guesses to...
Write a program that prompts the user for an even number from 2 to 100 until...
Write a program that prompts the user for an even number from 2 to 100 until the number 90 is encountered. Not including the 90, calculate the minimum value. In case you know what this means: DO NOT USE LISTS! We will look into the use of lists later. This has to be done in the python program. Here's what I have so far: inp = 0 min = 0 while inp != 90:     inp = int(input("Please enter an even...
The program will loop, asking the user for a bet amount from 0 to 50 (assume...
The program will loop, asking the user for a bet amount from 0 to 50 (assume dollars, you can use ints or longs). If the user types a 0 that means she wants to quit. Otherwise, accept the amount as their bet and simulate a slot machine pull. Your program will print out a line that looks like a slot machine result containing three strings. Some examples are:  BAR 7 BAR, 7 7 cherries, cherries BAR space, space BAR BAR, or...
Write a Python program that has a loop to continuously ask the user for a number,...
Write a Python program that has a loop to continuously ask the user for a number, terminating the loop when the number entered is -1. Inside the loop, 1.) display one asterisk(*) if the number is 1, 2.) two asterisk(**) if the number is 2 and 3.) "OTHER" if the number is any other number.
In Java: Write a program that prompts the user to enter a positive number until the...
In Java: Write a program that prompts the user to enter a positive number until the user input a negative number. In the end, the program outputs the sum of all the positive numbers. You should use do-while loop (not while, not for). You cannot use break or if statement in the lab. Hint: if the program adds the last negative number to your sum, you can subtract the last number from the sum after the loop.
Write a program using c++. Write a program that uses a loop to keep asking the...
Write a program using c++. Write a program that uses a loop to keep asking the user for a sentence, and for each sentence tells the user if it is a palindrome or not. The program should keep looping until the user types in END. After that, the program should display a count of how many sentences were typed in and how many palindromes were found. It should then quit. Your program must have (and use) at least four VALUE...
Write a Python Program Continue to ask the user to enter a POSITIVE number until they...
Write a Python Program Continue to ask the user to enter a POSITIVE number until they type DONE to quit. The program should DOUBLE each of the digits in the number and display the original entry AND the SUM of the doubled digits. Hint: Use the // and % operators to accomplish this. Print the COUNT of entries that were invalid Examples: if the user enters 93218, the sum of the doubled digits is 18+6+4+2+16 = 46. User Entry Output...
Write a C++ program that reads numbers from the user until the user enters a Sentinel....
Write a C++ program that reads numbers from the user until the user enters a Sentinel. Use a Sentinel of -999. Ignore all negative numbers from the user input. Do the following: Output the sum of all even numbers Output the sum of all odd numbers Output the count of all even numbers Output the count of all odd numbers You must use loops and numbers to do this. You must not use any arrays or vectors for this program.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT