Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- #include <stdlib.h>
- #include <math.h>
- #include <time.h>
- int main()
- {
- int lowerB;
- int upperB;
- int numCount;
- int rangeMod;
- int randOut;
- int i;
- int isGoing = 1;
- srand(time(NULL));
- printf("Random number generation: \n");
- //Return here after first if fails
- while(isGoing==1){
- printf("\nHow many numbers would you like to generate? ");
- scanf("%d",&numCount);
- if (numCount<=0){
- printf("\n\n---------------------------------------------------\nNumber must be greater than 0\n");
- }else{
- isGoing=0;
- }
- }
- isGoing=1;
- //Return here if either of the next two loops fail
- while(isGoing==1){
- printf("\nInput the lower limit of your number generation:");
- scanf("%d",&lowerB);
- printf("\nInput the upper limit of your number generation:");
- scanf("%d",&upperB);
- if (lowerB>upperB){
- printf("\n---------------------------------------------------\nYour upper limit must be larger than your lower limit.\n\n");
- }else{
- if (lowerB==upperB){
- printf("\n---------------------------------------------------\nYour limits must be different numbers.\n\n");
- }else{
- isGoing=0;
- }
- }
- }
- isGoing=1;
- printf("\nYour list of random numbers:\n");
- rangeMod = 1 + upperB - lowerB;
- for(i=0;i < numCount;i++){
- randOut = rand()%rangeMod;
- printf("\n%d",randOut);
- }
- //Restart prompt
- char moreNumbers;
- while(isGoing==1){
- printf("\nDo you want to generate more numbers? Y/N:");
- scanf("%c",&moreNumbers);
- if (moreNumbers=='Y'){
- printf("\n\n\n\n---------------------------------------------------");
- main();
- }else{
- isGoing=0;
- }
- }
- printf("\n\n\n");
- system("pause");
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement