Question
Part A) Define the function PrintValue() that takes two integer parameters and outputs the sum of all integers starting with the first and ending with
Part A)
Define the function PrintValue() that takes two integer parameters and outputs the sum of all integers starting with the first and ending with the second parameter, followed by a newline. The function does not return any value.
Ex: If the input is 3 5, then the output is:
12
Note: Assume the first integer parameter is less than the second.
#include
/* Your code goes here */
int main() { int numberA; int numberB;
cin >> numberA; cin >> numberB; PrintValue(numberA, numberB);
return 0; }
Part B)
Given integer variables seedVal and highestInput, generate five random numbers that are less than highestInput and greater than or equal to 0. Each number generated is output. Lastly, the average of the five numbers is output.
Ex: If highestInput is 16, then a possible output is:
7 15 13 3 10 Average: 9.6
Note: The input seeds are large integers that approximately equal the time in seconds since January 1, 1970.
#include
#include
#include
using namespace std;
int main() {
int seedVal;
int highestInput;
int rand1;
int rand2;
int rand3;
int rand4;
int rand5;
cin >> seedVal;
cin >> highestInput;
#include
int main() { int seedVal; int highestInput; int rand1; int rand2; int rand3; int rand4; int rand5; cin >> seedVal; cin >> highestInput; srand(seedVal); /* Your code goes here */ cout << rand1 << endl; cout << rand2 << endl; cout << rand3 << endl; cout << rand4 << endl; cout << rand5 << endl; cout << "Average: " << fixed << setprecision(1) << ((rand1 + rand2 + rand3 + rand4 + rand5) / 5.0) << endl; return 0; }
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started