Search code examples
c++c++11randomintegersrand

Copying a integer value from one integer into another


A very quick question l have to ask why the following will not work. I am an early programmer hence the reason l am asking for help.

I am trying to copy the value of num1gen into the integer of ballno1 and outputting it.

Code:

#include <iostream>
#include <stdlib.h>


using namespace std;

int main()

{
int ballno1 = 0;

srand(time(NULL));
int num1gen=(rand()%49+1);


ballno1 = ballno1 + num1gen;
cout<<ballno1<<" ";

}

Solution

  • To copy num1gen into ballno1 use ballno1 = num1gen; - very simple.

    PS: num1gen is not "integer" but "integer variable". Integer is the value.