Question

there is a function to create two random numbers between 1 and 25 and a function...

there is a function to create two random numbers between 1 and 25 and a function to add them together. add the prototypes correctly, call them from main correctly and output the results. The three functions should be subtractNumbers, multiplyNumbers, and divideNumbers. Remember that division won't always yield an integer so be sure to take care of that issue within the function (don't change the variable declarations).

  • Don't change the code that I've given you.
  • Follow the same pattern.

#include

#include // For rand and srand

#include // For the time function

using namespace std;

int chooseNumber();

int addNumbers(int, int);

const int MIN_VALUE = 1; // Minimum value

const int MAX_VALUE = 25; // Maximum value

unsigned seed = time(0);

int main()

{

srand(seed);

int firstNumber = chooseNumber();

int secondNumber = chooseNumber();

int sum = addNumbers(firstNumber, secondNumber);

cout << "The first number is " << firstNumber << endl;

cout << "The second number is " << secondNumber << endl;

cout << "The sum is " << sum;

return 0;

}

int chooseNumber()

{

int number; // To hold the value of the number

number = (rand() % (MAX_VALUE - MIN_VALUE + 1)) + MIN_VALUE;

return number;

}

int addNumbers (int number1, int number2)

{

int number = number1 +number2;

return number;

}

0 0
Add a comment Improve this question Transcribed image text
Answer #1

Code -


#include <iostream>
//added header file for rand and srand
#include <cstdlib>
//header file for time
#include <ctime>

using namespace std;

int chooseNumber();

int addNumbers(int, int);
//added function declaration subtractNumbers
int subtractNumbers(int, int);
//added function declaration multiplyNumbers
int multiplyNumbers(int, int);
//added function declaration divideNumbers
float divideNumbers(int, int);

const int MIN_VALUE = 1; // Minimum value

const int MAX_VALUE = 25; // Maximum value

unsigned seed = time(0);

int main()

{

srand(seed);

int firstNumber = chooseNumber();

int secondNumber = chooseNumber();

int sum = addNumbers(firstNumber, secondNumber);
//result for subtraction , call function subtractNumbers
int subtraction = subtractNumbers(firstNumber, secondNumber);
//result for multiplication , call function multiplyNumbers
int multiplication = multiplyNumbers(firstNumber, secondNumber);
//result for division , call function divideNumbers
float division = divideNumbers(firstNumber, secondNumber);

cout << "The first number is " << firstNumber << endl;

cout << "The second number is " << secondNumber << endl;

cout << "The sum is " << sum<<endl;
//result print
cout << "The subtraction is " << subtraction<<endl;
cout << "The multiplication is " << multiplication<<endl;
cout << "The division is " << division<<endl;

return 0;

}

int chooseNumber()

{

int number; // To hold the value of the number

number = (rand() % (MAX_VALUE - MIN_VALUE + 1)) + MIN_VALUE;

return number;

}

int addNumbers (int number1, int number2)

{

int number = number1 +number2;

return number;

}
//function define subtractNumbers
int subtractNumbers (int number1, int number2)

{
//subtract number and return the value
int number = number1 - number2;

return number;

}
//function define multiplyNumbers
int multiplyNumbers (int number1, int number2)

{
//mutiply number and return
int number = number1*number2;

return number;

}
//function define divideNumbers of return type as float because division can lead to floating point number
float divideNumbers (int number1, int number2)

{
//divide number type cast it to float and return
float number = (float)number1/number2;

return number;

}

Screenshot -

pls do give a like , thank you , If you have any doubt pls ask in comment section

Add a comment
Know the answer?
Add Answer to:
there is a function to create two random numbers between 1 and 25 and a function...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • Problem: Write a function named coinToss that simulates the tossing of a coin. When you call the function, it should ge...

    Problem: Write a function named coinToss that simulates the tossing of a coin. When you call the function, it should generate a random number in the range of 1 through 2. If the random number is 1, the function should display “heads.” If the random number is 2, the function should display “tails.” Demonstrate the function in a program that asks the user how many times the coin should be tossed and then simulates the tossing of the coin that...

  • 61. The following program is accepted by the compiler:         int sum( int x, int y...

    61. The following program is accepted by the compiler:         int sum( int x, int y )         {             int result;             result = x + y;            }                            T__   F__ 62. The following implementation is accepted by the compiler:         void product()         {             int a; int b; int c; int result;             cout << "Enter three integers: ";             cin >> a >> b >> c;             result = a * b * c;            ...

  • Using C++ Write two `void` functions.  These functions each take two  integer parameters.  The functions accomplish the following tasks....

    Using C++ Write two `void` functions.  These functions each take two  integer parameters.  The functions accomplish the following tasks. The first function prints out the numbers from the first argument up to and including the number passed as the second argument counting by the first argument (i.e. if the arguments are 2 and 10, the information below was given: #include <iostream> using namespace std; // function definitions// // main program int main() {   int firstNumber,secondNumber;   char countType, doAgain;   // we will do this...

  • In the following code, it gets hung up at    cout << "Number1 * Number2 =...

    In the following code, it gets hung up at    cout << "Number1 * Number2 = " << number1 * number2 << endl; giving an error of "no math for operator<<" what am i doing wrong? Thank you #include <iostream> #include <cctype> #include <cstdlib> using namespace std; class Rational //class for rational numbers (1/2, 5/9, ect..) {    public:        Rational(int numerator, int denominator);        Rational(int numberator);        Rational(); //default        friend istream& operator >>(istream& ins,...

  • Find and fix errors #include <iostream> #include <cstdlib> #include <ctime> using namespace std; const int MIN...

    Find and fix errors #include <iostream> #include <cstdlib> #include <ctime> using namespace std; const int MIN = 1; const int MAX = 10; int getRandom(int low, int high); int main() {    int random_num = 0; int player_num; int tries; int seed = static_cast<int>(time(0)); bool guessed = false;    srand(seed); // call the getRandom function below       tries = 4; while ( tries > 0 && !guessed ) { cout << "Enter a number within the range 1 to...

  • Remove srand(time(NULL)); from this C++ code so that it still finds random numbers correctly. Then, Write...

    Remove srand(time(NULL)); from this C++ code so that it still finds random numbers correctly. Then, Write a program that adds the following to the fixed code. • Add a function that will use the BubbleSort method to put the numbers in ascending order. – Send the function the array. – Send the function the size of the array. – The sorted array will be sent back through the parameter list, so the data type of the function will be void....

  • c++ /*This is the starter file for your final proficiency test This program has a function...

    c++ /*This is the starter file for your final proficiency test This program has a function that will generate a list of integers using the rand function. Your job is to fill the insertNum and oddCount functions.*/ #include <iostream> #include <ctime> using namespace std; //constants and function prototypes const int CAP = 100; int buildList(int[], int size); void printList(int[], int size); //your functions to implement /*This function finds even numbers in the list, and inserts a number before the even...

  • Write a c++ code into the given code  to find composite numbers from the given random number...

    Write a c++ code into the given code  to find composite numbers from the given random number list. The composite numbers is only counted once if there is a repeated number. I need to use this code and add on a code to find if the numbers generated is a composite function. Please help #include <cmath> #include <cstdlib> #include <ctime> #include <iostream> #include <vector> using namespace std; int main() {    srand(time(NULL)); int size_of_list = 0; // the number of random...

  • Programming Assignment 7 Implement a function named fibo that will get a 20 element initialized an...

    Programming Assignment 7 Implement a function named fibo that will get a 20 element initialized an array of zeros from the main function. It will set the array to the Fibonacci sequence. This sequence starts with 1 and 2 as the first 2 elements and each element thereafter is the sum of the previous two elements. (1, 2, 3, 5, 8, 13…). Add another function named findNum that will get the newly created array by fibo from the main function....

  • ​Declare an array with 1000 elements of type int Then in a loop generate 1000 random numbers and assign one to each element in the array The random numbers should be between 1 and 50 Then, prompt the user to enter a number, store this number in a local

    Rules to follow are:Declare an array with 1000 elements of type intThen in a loop generate 1000 random numbers and assign one to each element in the arrayThe random numbers should be between 1 and 50do not use rand or srand, use code is providedThen, prompt the user to enter a number, store this number in a local variable, the number should be safety checked using the GetInteger() functionThen, iterate through the array and determine how many times the user's...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT