Note that not every function has to have parameters. . Using this information, write a function called ask that asks the user for a number between 1 and 10 (inclusive). I have the program 99% accurate. The only problem is, and i know its an easy fix (i think), that when the number is in the good range (between 1 and 10) my code still displays the text "please follow directions" when it should not not even though i specified it too only when the number in an invalid choice. My code is as follows below.
in ask() {
int num;
cin>> num;
int ask;
ask=num;
return ask;
}
int main () {
int num=0;
while (( num<1) || (num>10)) {
num=ask();
cout<< endl;
cout<< Please enter a number from 1 to 10: ";
cout<< num;
cout<< endl;
cout<< "Please follow the directions!";
cout<< endl;
}
cout<< "you selected";
cout<< num;
cout<< endl;
return 0;
}
even though i specified it too only when the number in an invalid choice
I don't see that in your code.
What your code does is get a number from the user and then print a newline, followed by "Please enter a number from 1 to 10: ", followed by the number the user entered, followed by another newline, followed by "Please follow the directions!", followed by another newline.
Then it goes back to the top of the loop and checks if the number is less than 1 or bigger than 10 (and if it is, it repeats all of that).