Please write program in C++ Write a function called randCount with no parameters. The function should randomly generate 5 numbers between 8 to 15 and counts how many times a multiple of 2 occurred. Return the answer to the calling function. please write the program in C++
In this C++ program,
- We have defined a function named randCount
which has no parameters and returns the count of multiples of 2
from the 5 generated numbers in the range of 8 to 15.
- In the main, we are validating by calculating the function and
printing the returned output from the function.
(I believe that I made the code simple and understandable. If you still have any query, Feel free to drop me a comment)
Code:
#include <iostream>
using namespace std;
//Defined a function with no parameters and return an int
int randCount()
{
srand(time(NULL));
int count=0;//To store the count of multiples of 2
//Iterating to generate 5 elements
for(int i=0;i<5;i++)
{
//generating random numbers in range of 8 and 15
int number=(rand()%8)+8;
cout<<number<<" ";//"PLEASE REMOVE THIS, IT IS PURELY
FOR VALIDATION"
//Check if the generated number is a multiple of 2 and increment
the count
if(number%2==0)
count++;
}
return count; //return the count
}
int main()
{
cout<<endl<<"The count is
"<<randCount()<<endl;
return 0;
}
Please check the
compiled program and its output for your reference:
Output:
Hope this Helps!!!
Please upvote as well, If you got the answer?
If not please comment, I will Help you with that...
Please write program in C++ Write a function called randCount with no parameters. The function should...
•The multiplication operator works by summing some value, x, by another value, y. Write a function definition called multiply that takes two integer parameters to perform the operation described. Return the answer to the calling function. •Write a function called randCount with no parameters. The function should randomly generate 5 numbers between 8 to 15 and counts how many times a multiple of 2 occurred. Return the answer to the calling function. •Write a function called summary that takes as...
Please Use C++ for coding . . Note: The order that these functions are listed, do not reflect the order that they should be called. Your program must be fully functional. Submit all.cpp, input and output files for grading. Write a complete program that uses the functions listed below. Except for the printodd function, main should print the results after each function call to a file. Be sure to declare all necessary variables to properly call each function. Pay attention...
Note: The order that these functions are listed, do not reflect the order that they should be called. Your program must be fully functional. Submit all .cpp, input and output files for grading. Write a complete program that uses the functions listed below. Except for the printOdd function, main should print the results after each function call to a file. Be sure to declare all necessary variables to properly call each function. Pay attention to the order of your function...
Write a complete program that uses the functions listed below. Except for the printOdd function, main should print the results after each function call to a file. Be sure to declare all necessary variables to properly call each function. Pay attention to the order of your function calls. Be sure to read in data from the input file. Using the input file provided, run your program to generate an output file. Upload the output file your program generates. •Write a...
please write program in C++ Write a function called productEven, that takes as its parameter an input file. The function should read two integers and calculate the total product of only even numbers between them. Return the answer to the calling function. please write the program in C++
Write a function in the C++called summary that takes as its parameters an input and output file. The function should read two integers find the sum of even numbers, the sum of odd numbers, and the cumulative product between two values lower and upper. The function should return the sum of even, odd, ad cumulative product between the lower and upper values. Please write program in C++.
Write a function called productEven that takes as its parameter an input file. The function should read two integers and calculate the total product of only even numbers between them. Return the answer to the calling function. c++ program
Write a C++ program that contains a function called swapNums. This function takes two integer parameters, swaps them in memory, and outputs the results (there is nothing to return). In main, ask the user to enter two different numbers, output them as entered (step 1), call the function swapNums() which will output the numbers swapped (step 2), and then output the values again in main (step 3). You should have three sets of output. Sample run (10 and 5 were...
Please solve the program in C++(Recursive) Write a function called factorialIterative(). This function should take a single BIG integer (bigint) as its parameter n, and it will compute the factorial n! of the value and return it as its result (as a bigint). Write this functions using a loop (do not use recursion). 2. Write the factorial function again, but using recursion. Call this function factorialRecursive(). The function takes the same parameters and returns the same result as described in...
2. Write a program with three functions that will be called from the main function The functions will calculate the volume, area and perimeter of a cuboid. You should able to pass three parameters such as length, width and height, and a function will return area, another will return volume and final one will return perimeter. Define all your variables in floating point numbers 3. Modify the problem#2 to calculate the volume, area and perimeter in a sing le function...