In: Computer Science
Below is your code:
#include <iostream>
using namespace std;
int main() {
//variable to check number of times user entered the input
int count = 0;
//variable to hold the number entered by user
int number;
//while loop runs maximum of 10 times
while(count < 10) {
//increment the counter for each entry
count++;
//get input
cout<<"Enter an integer between 1 and 20: ";
cin>>number;
//if number not valid print error message and try again
if(number < 1 || number > 20) {
cout<<"Wrong number entered."<<endl;
} else {
//if valid number then come out of the loop
break;
}
}
//if count is 10, then assume 10 as user entry
if(count == 10) {
number = 10;
}
//printing cube of the entered number
cout<<"Cube of entered number: "<<(number*number*number)<<endl;
return 0;
}
Sample Output 1
Sample Output 2