Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /***************************************************************
- CSCI 240 Program 1 Spring 2019
- Programmer: Debojit Roy
- Section: 1
- Date Due: 2/19/2019
- Purpose: random number generator
- ***************************************************************/
- #include <iostream>
- #include <iomanip>
- #include <cstdlib>
- #include <ctime>
- using namespace std;
- int main()
- {
- int j, high, low, val, sum;
- double aveg, mycou;
- #define MAX_NUM 10
- #define MIN_NUM 2
- #define MAX_RANGE 50
- cout << fixed << setprecision(2);
- srand(24);
- sum=0;
- mycou = MIN_NUM + (rand() % (MAX_NUM - MIN_NUM + 1));
- cout << "The for loop will generate 10 numbers ... " << endl << endl;
- cout << "The numbers are ";
- //for loop
- for(j=1 ; j <= mycou ; j++)
- {
- val = rand() % 50+1;
- cout << " " << val;
- sum += val;
- aveg = sum/mycou;
- if (j==1)
- {
- high=val;
- low=val;
- }
- if(val > high)
- {
- high = val;
- }
- if( val < low)
- {
- low = val;
- }
- }
- cout << endl << "Smallest: " << setw(20) << low <<endl;
- cout << "Largest: " << setw(20) << high << endl;
- cout << "Sum: " << setw(24) << sum << endl;
- cout << "Average: " << setw(20) << aveg << endl;
- //while loop
- mycou = MIN_NUM + (rand() % (MAX_NUM - MIN_NUM + 1));
- cout << "The for loop will generate 10 numbers ... " << endl << endl;
- cout << "The numbers are ";
- j = 1;
- while (j <= mycou )
- {
- val = rand() % 50+1;
- cout << " " << val;
- sum += val;
- aveg = sum/mycou;
- j++;
- if (j==1)
- {
- high=val;
- low=val;
- }
- if(val > high)
- {
- high = val;
- }
- if( val < low)
- {
- low = val;
- }
- }
- cout << endl << "Smallest: " << setw(20) << low <<endl;
- cout << "Largest: " << setw(20) << high << endl;
- cout << "Sum: " << setw(24) << sum << endl;
- cout << "Average: " << setw(20) << aveg << endl;
- //do while loop
- mycou = MIN_NUM + (rand() % (MAX_NUM - MIN_NUM + 1));
- cout << "The for loop will generate 10 numbers ... " << endl << endl;
- cout << "The numbers are ";
- j = 1;
- do
- {
- val = rand() % 50+1;
- cout << " " << val;
- sum += val;
- aveg = sum/mycou;
- j++;
- }
- while (j <=mycou);
- if (j==1)
- {
- high=val;
- low=val;
- }
- if(val > high)
- {
- high = val;
- }
- if( val < low)
- {
- low = val;
- }
- cout << endl << "Smallest: " << setw(20) << low <<endl;
- cout << "Largest: " << setw(20) << high << endl;
- cout << "Sum: " << setw(24) << sum << endl;
- cout << "Average: " << setw(20) << aveg << endl;
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement