Hi,
I'm a student taking a beginner's c++ course. I am trying to write a program that performes simple math operations on random numbers. I am using the
srand(int(time( 0))); function to generate the random numbers. I have two variables that I'm using to perform the operations upon. I was wondering if there was a way to tell one of the variables to be less than the other so that negative answers are not generated during subtraction and division. Here is a snippet:
Don't know how far off I am....like I said just a beginner. Any advice would be helpful.
I'm a student taking a beginner's c++ course. I am trying to write a program that performes simple math operations on random numbers. I am using the
srand(int(time( 0))); function to generate the random numbers. I have two variables that I'm using to perform the operations upon. I was wondering if there was a way to tell one of the variables to be less than the other so that negative answers are not generated during subtraction and division. Here is a snippet:
Code:
srand(int(time(0))); vara = 1 + rand() % (1000 - 1 + 1); varb = 1 + rand() % (1000 - 1 + 1); answera = 0; cout << "What is " << vara << '-' << varb << '?' << endl; cin >> response; answera = vara - varb;
Comment