Waiting for answer This question has not been answered yet. You can hire a professional tutor to get the answer.

QUESTION

Write a program that will do the following steps:

Write a program that will do the following steps:

- generate 2 random integer numbers between 1 and 20 inclusive ( 1-20, no 0 values)

- calculate the square root of each number

- calculate the average of the 2 numbers

- print the 2 random numbers

- print the square root of each random number with 3 digits after the decimal point

- print the average of the 2 numbers with 1 digit after the decimal point

Example program output:

The two random numbers are 2 and 3

The average is 2.5

The square root of 2 is 1.214

The square root of 3 is 1.372

I write the my code but I do not know how I need to write the square roots. This is my code. Please someone explain to me step by step.

#include <iostream>

#include <ctime> // Needed for the true randomization

#include <cstdlib>

#include<cmath>

#include<iomanip>

using namespace std;

int main ()

{

int xRan=0;

int xRan1=0;

double root1;

double root2;

double average;

srand( time(0)); // This will ensure a really randomized number by

using computer clock

xRan=rand()%20 + 1; // Randomizing the number between 1-15.

xRan1=rand()%20 + 1;

cout << "The two random numbers between 1-20 are: " << xRan;

cout<<" and "<<xRan1<<endl;

return 0;

}

Show more
LEARN MORE EFFECTIVELY AND GET BETTER GRADES!
Ask a Question