Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Set each value that the rand() generates to an int. 2. Add the 3 numbers togethe

ID: 3794195 • Letter: S

Question

Set each value that the rand() generates to an int.

2. Add the 3 numbers together and print the sum

3. Hint: Create 3 int variables.

/*Shawn Higgins
2/16/17
In class assignment 3-27
*/
// This program demonstrates using the C++ time function
// to provide a "seed" for the random number generator.
#include <iostream>
#include <cstdlib> // header file needed to use srand and rand
#include <ctime> // header file needed to use time
using namespace std;

int main ()
{
   unsigned seed; // Random generator seed

   // Use the time function to get a "seed" value for strand
   seed = time(0);
   srand(seed);

   // Now generate and print three random numbers
   cout << rand() <<"       " ;
   cout << rand() <<"       " ;
   cout << rand() << endl;

   int

     
   char c;
   cout <<" Type any Character";
   cin >> c;
   return 0;
}

Explanation / Answer

/*Shawn Higgins
2/16/17
In class assignment 3-27
*/
// This program demonstrates using the C++ time function
// to provide a "seed" for the random number generator.
#include <iostream>
#include <cstdlib> // header file needed to use srand and rand
#include <ctime> // header file needed to use time
#define MAX_RANGE 10000
using namespace std;
int main ()
{
unsigned seed; // Random generator seed
// Use the time function to get a "seed" value for strand
seed = time(0);
srand(seed);
  
  
// Now generate and print three random numbers
int n1=rand()%MAX_RANGE;
int n2=rand()%MAX_RANGE;
int n3=rand()%MAX_RANGE;
int sum=n1+n2+n3;
cout << "Numbers are : " << n1<<","<<n2<<","<<n3<<endl ;
cout << "Total sum : " << sum<<endl ;

char c;
cout <<" Type any Character";
cin >> c;
return 0;
}

Output check url http://ideone.com/zL6dI5

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote