Computers and Technology

Here is the starting code for your assignment. As you can see, so far there is a function to create two random numbers between 1 and 25 and a function to add them together. Your assignment is to create three more functions, 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.
Don't use tools that we haven't studied.
// This program adds, subtracts, multiplies, and divides two random numbers
#include
#include // For rand and srand
#include // For the time function
using namespace std;
// Function declarations
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()
{
// Seed the random number generator.
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()
{
// Variable
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;
}
Notice that number is used as a variable in more than one function. This works because number is a variable.

answer
Answers: 1

Other questions on the subject: Computers and Technology

image
Computers and Technology, 22.06.2019 08:10, Bearboy5957
Ihave a music player on my phone. i can buy songs, add them to playlists and play them. obviously it would be redundant to store each song in each playlist; each playlist is just a list of pointers to the songs. for this lab you will simulate this behavior. your program will need to have options to: add songs to the system library (you will store the text of the first line of the song, rather than the audio) add playlists add songs to a playlist list playlists play a playlist list all of the songs in the library with a count of how many times each song has been played remove a song from a playlist remove a playlist remove a song from the library (and thus from all playlists that contain it) note that we will not be checking many error cases. in real programming this would be bad, you should usually try to recognize and respond to as many types of errors as you can. in the context of class we are trying to acquaint you with as many concepts as possible, so for the sake of educational efficiency we will not be checking most errors in this lab, you may assume that your user provides correct input. you may add all appropriate error testing if you wish, but we will not be testing for it.
Answers: 2
image
Computers and Technology, 23.06.2019 23:00, GreenHerbz206
Computer programming is one type of what career
Answers: 1
image
Computers and Technology, 24.06.2019 13:30, nina288
What process should be followed while giving a reference? sam has given a reference of his previous manager in his resume. sam should him in advance that the potential employers will him.
Answers: 1
image
Computers and Technology, 24.06.2019 18:20, seema12
7. design a circuit with three inputs (x, y, and z) representing the bits in a binary number, and three outputs (a, b, and c) also representing bits in a binary number. when the input is 1, 2, or 3, the binary output should be one lesser than the input. when the input is 4, 5, or 6, the binary output should be one greater than the input. when the input is 0, the output is 0, and when the input is 7, the output is 7. show your truth table, all computations for simplification, and the final circuit.
Answers: 2
Do you know the correct answer?
Here is the starting code for your assignment. As you can see, so far there is a function to create...

Questions in other subjects:

Konu
Mathematics, 10.03.2021 21:50