Hello

I have a > b(for example)

I need to generate random number x that belongs from a to b

for example a = 9, b = 16

x has to be x > 9 and x < 16

I use cstdlib.. but can't guess how to do it (using rand())

can you do it, without any while or for??

this is a part of a huge program...

so I have to do it carefully, this my program doesn't work..

I think the reason is that...

this is a part of my program ...

the excercise was about a game

in that game one guy think of a number,and can say hotter or colder, and the second one tries to guess it very fast...

this code is the part of second that have to call Guess(G) very few times

but analyzing the mind of player wasn't easy

for example first's number was 12(and he thought about number between 1 and 20)

and it can said 5 11 15, or 5 9 11, or 18 4 16 or 11 15 13

I got to write a code that have to know what number should be next

analyzing temperature of each number....

in both cases hot or cold

I thought about debugging this program, but I still don't know how to GDB it(??)

to see where it goes, and what are my variables' values at the each line...

this is my nightmare

even if you can't solve it, let's discuss it

command work is always the best

```
#include<cstdlib>
#include"grader.h"
#include<iostream>
#include<ctime>
using namespace std;
int HC(unsigned int N)
{
unsigned short int n = 0;
unsigned short int G;
unsigned short int one_past_of_G=1;
unsigned short int previous_of_past_of_G =1;
short int temper_of_previous = 0;
short int temper_of_pastpast = 0;
register int i;
int test;
G = (rand() % N)+1;
short int temper = Guess(G);
temper++;
one_past_of_G = G;
srand(time(NULL));
G = (rand() % N)+1;
while(temper != 0 || Guess(G) != 0){
n++;
temper = Guess(G);
if(n > 2){
if(temper == 1){
if(previous_of_past_of_G < one_past_of_G && one_past_of_G < G){
if(temper_of_previous == 1){
if(temper_of_pastpast == 1){
for(i = 0; test <= G+5 && test > one_past_of_G || i < 10; i++){
test = ((rand()%one_past_of_G-(one_past_of_G))+(G +1));
if(test > one_past_of_G && test < G+5){
G = test;
}
}
}else{
G = ((rand()%previous_of_past_of_G-(previous_of_past_of_G))+(G +1));
}
}
cout << "(temper == 1){\n" <<
"\tif(previous_of_past_of_G < one_past_of_G && one_past_of_G < G) \n" << G;
}
else if(previous_of_past_of_G > one_past_of_G && one_past_of_G < G){
if(temper_of_previous == -1){
if(temper_of_pastpast == 1){
if(G <= previous_of_past_of_G){
G = ((rand()%G-(G))+(previous_of_past_of_G+1));
}else{
G = ((rand()%previous_of_past_of_G-(previous_of_past_of_G))+(G+1));
}
}
}
cout << "(temper == 1){\n" <<
"\tprevious_of_past_of_G > one_past_of_G && one_past_of_G < G \n" << G;
}else if(previous_of_past_of_G < one_past_of_G && one_past_of_G > G){
if(temper_of_previous == -1){
if(temper_of_pastpast == 1){
if(G <= previous_of_past_of_G){
G = ((rand()%G-(G))+(one_past_of_G+1));
}else if(G > previous_of_past_of_G){
G = ((rand()%previous_of_past_of_G-(previous_of_past_of_G))+( one_past_of_G +1));
}
}
}
cout << "(temper == 1){\n" <<
"\tprevious_of_past_of_G < one_past_of_G && one_past_of_G > G \n" << G;
}else if(previous_of_past_of_G > one_past_of_G && one_past_of_G > G){
if(temper_of_previous == 1){
if(temper_of_pastpast == 1){
G = ((rand()%G-(G))+(one_past_of_G+1));
}else{
G = ((rand()%G-(G))+(previous_of_past_of_G+1));
}
}
cout << "(temper == 1){\n" <<"\tprevious_of_past_of_G > one_past_of_G && one_past_of_G > G \n" << G;
}
}
}else if(n < 2){
if(temper == 1){
if(one_past_of_G <= G){
G = ((rand()%one_past_of_G-(one_past_of_G))+(G+1));
}
else if(one_past_of_G > G ){
G = ((rand()%G )+1);
}
cout << "****ing 2 \n";
}else if(temper == -1){
if(one_past_of_G <= G){
G = ((rand()%G )+1);
}else if(one_past_of_G > G ){
G = ((rand()%one_past_of_G-(one_past_of_G))+(G+1));
}
}
//cout << "fuching 2 \n";
}
if((n > 2) && temper == -1){
if(previous_of_past_of_G < one_past_of_G && one_past_of_G < G){
if(temper_of_previous == 1){
for(i = 0; test < G && test > previous_of_past_of_G || i < 6; i++){
test = ((rand()%previous_of_past_of_G-(previous_of_past_of_G))+(G+1));
if(test < G && test > previous_of_past_of_G)
{
G = test;
}
}
}else if(temper_of_previous == -1){
G = ((rand()%one_past_of_G+1));
}
cout << "fuching cold!! 1<2<3\n";
}else if(previous_of_past_of_G > one_past_of_G && one_past_of_G < G){
if(temper_of_previous == 1){
G = ((rand()%one_past_of_G+1));
}else if(temper_of_previous == -1){
for(i = 0; test < previous_of_past_of_G && test > one_past_of_G || i < 6; i++){
test = ((rand()%one_past_of_G-(one_past_of_G))+(previous_of_past_of_G+1));
if(test < G && test > previous_of_past_of_G)
{
G = test;
}
}
}
cout << "fuching cold!! 1>2<3\n";
}else if(previous_of_past_of_G < one_past_of_G && one_past_of_G > G){
if(temper_of_previous == 1){
if(G <= previous_of_past_of_G){
for(i = 0; test < one_past_of_G && test > G || i < 6; i++){
test = ((rand()%G-(G))+(one_past_of_G+1));
if(test < one_past_of_G && test > G){
G = test;
}
}
}else if(G > previous_of_past_of_G){
for(i = 0; test < one_past_of_G && test > previous_of_past_of_G || i < 6; i++){
test = ((rand()%previous_of_past_of_G-(previous_of_past_of_G))+(one_past_of_G+1));
if(test < one_past_of_G && test > G){
G = test;
}
}
}
}
cout << "fuching cold!! 1<2>3\n";
}else if(previous_of_past_of_G > one_past_of_G && one_past_of_G > G){
if(temper_of_previous == -1){
G = (rand() % G) + G;
}
if(temper_of_previous == 1)
for(i = 0; test < one_past_of_G && test > G || i < 6; i++){
test = ((rand()%G-(G))+(one_past_of_G+1));
if(test < one_past_of_G && test > G){
G = test;
}
}
cout << "fuching cold!! 1>2>3\n";
}
}
if(n > 1){
previous_of_past_of_G = one_past_of_G;
temper_of_pastpast = temper_of_previous;
}
one_past_of_G = G;
temper_of_previous = temper;
//cout << "G = " << G;
//cout << "one past of G = " << one_past_of_G << '\n';
//cout << "previous of past of G = " << previous_of_past_of_G << '\n';
}
cout << "k = " << k << "\n\n";
cout << "n = " << n << '\n';
cout << "real = " << real << "\n\n";
return G;
}
```