Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Using C++ Note that not every function has to have parameters. For example, you

ID: 3569090 • Letter: U

Question

Using C++

Note that not every function has to have parameters. For example, you have been creating the
function main since the beginning, and it is a function without parameters. Using this
information, write a function called ask that asks the user for a number between 1 and 10
(inclusive). Use the following code in main to test it:

int num = 0;
while ((num < 1) || (num > 10)) {
num = ask();
}
cout << "You selected " << num << endl;
return 0;

Sample output:
Please enter a number between 1 and 10 (inclusive): 11
Please enter a number between 1 and 10 (inclusive): 0
Please enter a number between 1 and 10 (inclusive): -11
Please enter a number between 1 and 10 (inclusive): 1111
Please enter a number between 1 and 10 (inclusive): 10
You selected 10

Explanation / Answer

#include<iostream>

using namespace std;

int ask()

{

    int i;

cout << "Please enter a number between 1 and 10 (inclusive):" ;

   cin >> i;

   return i;

}

int main()

{

int num = 0;
while ((num < 1) || (num > 10)) {
num = ask();
}
cout << "You selected " << num << endl;
return 0;

}

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote