Advertisement
Guest User

Untitled

a guest
Jan 24th, 2017
99
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.06 KB | None | 0 0
  1. #include <stdio.h>
  2. #include <stdlib.h>
  3. #include <math.h>
  4. #include <time.h>
  5.  
  6. int main()
  7. {
  8. int lowerB;
  9. int upperB;
  10. int numCount;
  11. int rangeMod;
  12. int randOut;
  13. int i;
  14. int isGoing = 1;
  15. srand(time(NULL));
  16. printf("Random number generation: \n");
  17. //Return here after first if fails
  18. while(isGoing==1){
  19. printf("\nHow many numbers would you like to generate? ");
  20. scanf("%d",&numCount);
  21. if (numCount<=0){
  22. printf("\n\n---------------------------------------------------\nNumber must be greater than 0\n");
  23. }else{
  24. isGoing=0;
  25. }
  26. }
  27. isGoing=1;
  28. //Return here if either of the next two loops fail
  29. while(isGoing==1){
  30. printf("\nInput the lower limit of your number generation:");
  31. scanf("%d",&lowerB);
  32. printf("\nInput the upper limit of your number generation:");
  33. scanf("%d",&upperB);
  34.  
  35. if (lowerB>upperB){
  36. printf("\n---------------------------------------------------\nYour upper limit must be larger than your lower limit.\n\n");
  37.  
  38. }else{
  39.  
  40. if (lowerB==upperB){
  41. printf("\n---------------------------------------------------\nYour limits must be different numbers.\n\n");
  42. }else{
  43. isGoing=0;
  44. }
  45. }
  46. }
  47. isGoing=1;
  48. printf("\nYour list of random numbers:\n");
  49. rangeMod = 1 + upperB - lowerB;
  50. for(i=0;i < numCount;i++){
  51. randOut = rand()%rangeMod;
  52. printf("\n%d",randOut);
  53. }
  54. //Restart prompt
  55. char moreNumbers;
  56. while(isGoing==1){
  57. printf("\nDo you want to generate more numbers? Y/N:");
  58. scanf("%c",&moreNumbers);
  59. if (moreNumbers=='Y'){
  60. printf("\n\n\n\n---------------------------------------------------");
  61. main();
  62. }else{
  63. isGoing=0;
  64. }
  65. }
  66. printf("\n\n\n");
  67. system("pause");
  68.  
  69. return 0;
  70. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement