Random Numbers Assignment with error found

Hello, so I was assigned to write a program that allows a person to input two numbers and find the sum of the two.
My teacher gave us the beginning of the code to start, which is
1
2
3
4
5
6
7
8
9
10
11
12
#include <iostream>
#include <cstdlib>
#include <cmath>
#include <ctime>
using namespace std;

int main() {
 unsigned seed = time(0);
 unsigned short FirstRandom, SecondRandom;

 srand(seed);
 FirstRandom = (rand() % 901) + 100;


and I added this to it...
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
  #include <iostream>
#include <cstdlib>
#include <cmath>
#include <ctime>
#include <iomanip>
using namespace std;

int main() {
    unsigned seed = time(0);
    unsigned long FirstRandom, SecondRandom, total;
    
    srand(seed);
    FirstRandom = (rand() % 901) + 100;
    SecondRandom = (rand() % 901) + 100;
    total = FirstRandom + SecondRandom;

    //Welcome Message
    cout<<"Hello and welcome to the tutoring center.\n\nIn order to get started with your first addition problem please enter the first number: "<<endl;
    cin>>FirstRandom;
    
    cout<<"\nNow please enter the second number: "<<endl;
    cin>>SecondRandom;

   //Waits for student to press Enter in order to proceed
    cout<<"\nNow once you are done solving the problem yourself, please press the enter button to receive the answer."<<endl;
    cin.get();
    
    //The Answer
    
    cout<<"The sum of "<< setw(5) << FirstRandom << "and";
    cout<< setw(5) << SecondRandom << "is " << setw(5) << total <<endl;
    
    return 0;
]


but on xCode it gives me this error (implicit conversion loses integer precision: "time_t" (aka 'long') to 'unsigned int') on the statement
 
unsigned seed = time(0);


Please help,
thanks!
Either do this:
 
unsigned seed = unsigned(time(0));


Or ditch the variable altogether
 
srand(time(0));


Or use a C++ random engine, since you use C++:
http://www.cplusplus.com/reference/random/
1
2
std::mt19937 rng;
rng.seed(std::chrono::steady_clock::now());
Topic archived. No new replies allowed.