Set each value that the rand generates to an int 2 Add the 3
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;
}
Solution
/*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

