### Write a function that will do this

Hello everyone,

so i am working on a program which is basically this
#include <cstdlib>
#include <iostream>
using namespace std;

int main() {

srand(time(0)); // to get new random numbers for each run

int first, last;
first = 0;
last = 9;
for (int r = 1; r <= 100; r+=10) {
cout<<"The range for this row is: "<<first+r<<" to "<<last+r<<": ";
for(int c = 1; c <= 10; c++) {
cout<<randNum(first+r,last+r)<<" ";
}
cout<<endl;
}
cout << endl;

return 0;

}

but i have to write the function randNum so that the output will be like this ..

The range for this row is: 1 to 10: 5 4 10 2 7 9 1 8 9 6
The range for this row is: 11 to 20: 20 15 16 11 20 11 13 13 13 11
The range for this row is: 21 to 30: 28 28 25 30 30 25 29 28 29 28
The range for this row is: 31 to 40: 39 33 34 40 37 40 31 37 37 31
The range for this row is: 41 to 50: 44 48 45 50 50 47 42 44 49 46
The range for this row is: 51 to 60: 55 59 55 51 60 56 57 60 53 56
The range for this row is: 61 to 70: 67 63 68 70 65 64 61 65 62 70
The range for this row is: 71 to 80: 77 76 79 72 77 79 80 78 72 78
The range for this row is: 81 to 90: 85 86 88 90 89 87 85 85 86 90
The range for this row is: 91 to 100: 100 95 92 98 94 96 93 95 92 95

can anyone please help me do that ? or tell me what i am doing wrong ..
Use rand to implement randNum http://www.cplusplus.com/reference/cstdlib/rand/
so how would you do it ?

i'm pretty new to this
In the example code, line 3, you replace 30 by last-first+1 and 1985 by first+r
So wha would be the new code ?
Topic archived. No new replies allowed.