By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
424,968 Members | 1,620 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 424,968 IT Pros & Developers. It's quick & easy.

how would i use while loop to create a range between 100-299 of rndom numbers

P: 2
so im tryin to create a program that generates 10 random numbers that display on screen that ranges from 100 to 299 im brand new to C++ and could use some help this is what i have so far it just keeps closing on me befor i get to input a number
Expand|Select|Wrap|Line Numbers
  1. #include <iostream>
  2. #include <cstdlib>
  3. #include <ctime>
  4. using namespace std;
  5.  
  6. int main()
  7. {
  8.  
  9.     {
  10.         srand(static_cast<unsigned int>(time(0))); //seed random number generator
  11.         int randomNumber = rand(); //generate random number
  12.         int number = (randomNumber % 299) + 100; // get a number between 100 and 299
  13.         cout << "Your number is between 100 & 199 " <<              number << endl;
  14.         return 0;
  15.  
  16.         system("pause");
  17.     }
  18.  
  19.     system("pause");
  20. }
Nov 6 '15 #1
Share this Question
Share on Google+
1 Reply


weaknessforcats
Expert Mod 5K+
P: 9,197
The program never gets to your system("pause") because you return right after you display your result.

Probably you see a blink and its over.

Take out that return.
Nov 6 '15 #2

Post your reply

Sign in to post your reply or Sign up for a free account.