Anonymous Anonymous - 1 month ago
468 0

No description

C++

CS170ExtraCredit

#include <iostream>
#include <cstdlib>
#include <ctime>
#include <cmath> 
using namespace std;

int main() {
    //Variable declarations
    int boundL, boundU, randNum, x=1, leftNum, rightNum, n, p, leftPow, rightPow;
    srand(time(0));
    cout << "Enter lower bound: " << endl;
    cin >> boundL;
    cout << boundL << endl;
    cout << "Enter upper bound: " << endl;
    cin >> boundU;
    cout << boundU << endl;
    
    //check for max size
    
    
    
    //create random integer
    do{
        randNum = (rand()%boundU);
        //cout << "Try " << x << " gives randNum: " << randNum << endl;
        //x++;
    } while (randNum < boundL || randNum > boundU);
    
    //test part
    randNum = 12345;
    
    n = 3;
    p = n - 1;
    leftPow = pow(10.0, n);
    rightPow = pow(10.0, p);
    cout << "leftPow: " << leftPow << endl;
    cout << "rightPow: " << rightPow << endl;
    
    cout << "Generated Number: " << randNum << endl;
//int left(x){
    leftNum = randNum / leftPow;
    cout << "Left part: " << leftNum << endl;
//}

//int right(y){
  rightNum = randNum % rightPow;
  cout << "Right part: " << rightNum << endl;
//}
    
    return 0;
    
}

/*

Develop a program that will prompt the user for the lower and the upper bound of a positive range of

integers and generate a random integer in this range. Limit the size of the range to the predefined

constant RAND_MAX. Then visit each position of the integer number starting at position 2, extract the

digit at this position and create two other integers: left part, an integer consisting of the digits to the left

of the extracted digit (in the order these digits are in the original integer) and right part, an integer

consisting of the digits to the right of the extracted digit (in the order in which they appear in the

original integer). Ask the user to change the extracted digit. Then create a new integer from the left part

followed by the new digit followed by the right part. Your program should be able to work correctly

with any number consisting of 3 to 9 digits.

*/