Use A While Loop To Write A Program That Calculates The Sum Of \( \Mathrm{N} \) Integers Entered By The User. \( \Mathrm{N} \) Is A Computer Generated Random Number Between
Use a while loop to write a program that calculates the sum ofintegers entered by the user.is a computer generated random number between 3 and 10 (both inclusive). Provide 4 valid test cases. No invalid test cases. Note: Use the following libraries for rand(),srand(), and time() support. \#include\#includeUse this for setting a seed: srand(time(NULL)) Use this for generating a random number:
Use A While Loop To Write A Program That Calculates The Sum Of \( \Mathrm{N} \) Integers Entered By The User. \( \Mathrm{N} \) Is A Computer Generated Random Number Between 3 And 10 (Both Inclusive). Provide 4 Valid Test Cases. No Invalid Test Cases. Note: Use The Following Libraries For Rand(),Srand(), And Time() Support. \#Include <Cstdlib \( > \)
Expert Answer
1st step
All steps
Answer only
Step 1/3
Code:
Here’s a program that calculates the sum of N integers entered by the user. N is a random number between 3 and 10 (inclusive).
#include <iostream>
#include <cstdlib>
#include <ctime>
using namespace std;
int main()
{
srand(time(NULL));
int n = 3 + rand() % 8;
int sum = 0;
int num;
cout << “Enter “ << n << ” numbers: “;
for (int i = 0; i < n; i++)
{
cin >> num;
sum += num;
}
cout << “The sum of the “ << n << ” numbers is “ << sum << endl;
return 0;
}
OR