39.0k views
2 votes
Compose a C++ function named getSpeed that uses a reference parameter variable named speed to accept an integer argument. The function should prompt the user to enter a number in the range of 20 through 70. The value entered by the user should be validated and stored in the parameter variable. Set the parameter variable to zero if the user enters a number outside the range of 20 through 70. void getSpeed (int &speed)

User Satara
by
4.7k points

1 Answer

1 vote

// Making the function

void getSpeed(int &speed){

// initialize the variable to take input

int input =0;

cout << " Enter the Number in range of 20 through 70 : "<<;

cin>>input;

// validate the input

if(input>=20 && input<=70)

speed = input;

else

speed = 0;

}

User Llullulluis
by
5.2k points