/***************************************** * * * * * CSCI 1470, Fall 2005 * * Machine Problem:MP2AB * * Purpose: Generate two random numbers * * and then input them in various math * * equations. * *****************************************/ #include #include #include #include using namespace std; int main(void) { //Declare variables unsigned seed; float rand1, rand2, sum, difference, product, quotient, absofdiff, logofsqrtofquo; //Ask user for seed number cout << "Enter a seed:"; cin >> seed; cout << endl; //Generate random numbers using the user defined seed srand(seed); rand1 = 1 + rand()% 100; rand2 = 1 + rand()% 100; //Do mathmatical equations with random numbers sum = rand1 + rand2; difference = rand1 - rand2; product = rand1 * rand2; quotient = rand1 / rand2; absofdiff = abs(difference); logofsqrtofquo = log( sqrt(quotient) ); // Display the random numbers and the answers to the mathmatical equations cout << "First random number (1 to 100) is:" << setprecision(2) << fixed << rand1 << endl << endl; cout << "Second random number (1 to 100) is:" << setprecision(2) << fixed << rand2 << endl << endl; cout << "Sum of the two random numbers is:" << setprecision(2) << fixed << sum << endl << endl; cout << "Difference of the two random numbers is:" << setprecision(2) << fixed << difference << endl << endl; cout << "Product of the two random numbers is:" << setprecision(2) << fixed << product << endl << endl; cout << "Quotient of the two random numbers is:" << setprecision(2) << fixed << quotient << endl << endl; cout << "The absolute value of the difference is:" << setprecision(2) << fixed << absofdiff << endl << endl; cout << "Logarithm (natural) of the square root of the quotient is:" << setprecision(2) << fixed << logofsqrtofquo << endl << endl; return 0; }//end of function main