i was wondering if anyone could help me. im tacking a c++ course right now and im kinda stuck on one of my labs. see the current lab is asking me to use a myrand() function which i was supposed to have made in another lab. it needed the user to enter a high and low value and the random number had to either be between the high and low values or the high and low themselves. i got close but could not get it exactly. i have tried random = (low+rand() % (high-low+1)) and random = rand()/low%high as well as a few other pointless ones. all i need is a real basic line of code to make it happen, so i can mave on with my current lab. if anyone can help i would really appreciate it.
it might help if i included my code : // note: he wanted like twenty random numbers ^_^ #include <iostream> #include <cstdlib> #include <ctime> using namespace std; const char space = ' '; int myrandom(int low, int high); int random; int main() { int high, low; cout << "This program will display 9 to 10 random values between a high and low number." << '\n' << '\n'; cout << "Enter the highest possible value: "; cin >> high; cout << '\n' << "Enter the lowest possible value: "; cin >> low; srand(time (0)); myrandom(low, high); cout << '\n' << '\n'; return 0; } int myrandom(int low, int high) { random = rand()/low%high ; random += 1; if(random < low) { random = random + rand()%2; random += 1; random; cout << random << space; } else { cout << random << space; random = rand()/low%high; random; if(random < low) { random = random + rand()%2; random += 1; random; cout << random << space; } else { cout << random << space; } } random = rand()/low%high;//line 82 if(random < low) { random = random + rand()%2; random += 1; random; cout << random << space; } else { cout << random << space; random = rand()/low%high; random; if(random < low) { random = random + rand()%2; random += 1; random; cout << random << space; } else { cout << random << space; } } random = rand()/low%high;//line 82 if(random < low) { random = random + rand()%2; random += 1; random; cout << random << space; } else { cout << random << space; random = rand()/low%high; random; if(random < low) { random = random + rand()%2; random += 1; random; cout << random << space; } else { cout << random << space; } } random = rand()/low%high;//line 82 if(random < low) { random = random + rand()%2; random += 1; random; cout << random << space; } else { cout << random << space; random = rand()/low%high; random; if(random < low) { random = random + rand()%2; random += 1; random; cout << random << space; } else { cout << random << space; } } random = rand()/low%high;//line 82 if(random < low) { random = random + rand()%2; random += 1; random; cout << random << space; } else { cout << random << space; random = rand()/low%high; random; if(random < low) { random = random + rand()%2; random += 1; random; cout << random << space; } else { cout << random << space; } } random = rand()/low%high;//line 82 if(random < low) { random = random + rand()%2; random += 1; random; cout << random << space; } else { cout << random << space; random = rand()/low%high; random; if(random < low) { random = random + rand()%2; random += 1; random; cout << random << space; } else { cout << random << space; } } return random; }