Instructions
Requirements and Specifications
Source Code
#include <iostream>
/*
FUNCTION 1
*/
int function1()
{
// ask user for integer
int N;
std::cout << "Please enter an integer: ";
std::cin >> N;
return N;
}
void function2(int &N)
{
// ask user for integer
std::cout << "Please enter an integer: ";
std::cin >> N; // save user's input into variable N
}
int function3(int M)
{
// create variable to store input
int N;
// Create a while-loop that will be executed until the user enters a number higher than M
while (true)
{
// ask for number
std::cout << "Please enter an integer larger than " << M << ": ";
std::cin >> N;
if (N > M) // good
break;
else
std::cout << "Invalid number." << std::endl;
}
return N;
}
void function4(int N)
{
std::cout << "The number is: " << N << std::endl;
}
void function5(int M, int N)
{
// We assume that N is always greater than M
// We print all the numbers between M and N, inclusive
std::cout << "The number between " << M << " and " << N << " (inclusive) are: ";
for (int n = M; n <= N; n++)
{
std::cout << n << " ";
}
std::cout << std::endl;
}
int main()
{
// Declare N1, N2, and N3
int N1, N2, N3;
// Call function 1
N1 = function1();
// Call function4 to print N1
function4(N1);
// Call function2 to enter N2
function2(N2);
// function 4 to print N2
function4(N2);
// Call function 3 with N2 and N3
N3 = function3(N2);
// Call function 4 to print N3
function4(N3);
// Call function 5 with N2 and N3
function5(N2, N3);
}