1answer.
Ask question
Login Signup
Ask question
All categories
  • English
  • Mathematics
  • Social Studies
  • Business
  • History
  • Health
  • Geography
  • Biology
  • Physics
  • Chemistry
  • Computers and Technology
  • Arts
  • World Languages
  • Spanish
  • French
  • German
  • Advanced Placement (AP)
  • SAT
  • Medicine
  • Law
  • Engineering
umka21 [38]
3 years ago
13

4. Compose a C function named getSpeed that uses a reference parameter variable named speed to accept an integer argument. The f

unction should prompt the user to enter a number in the range of 20 through 70. Set the parameter variable to zero if the user enters a number outside the range of 20 through 70.
Computers and Technology
1 answer:
Pachacha [2.7K]3 years ago
6 0

Answer:

void getSpeed(int& speed)  

//the function with reference parameter speed and & denote a reference

{  //prompts user to enter a number

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

 cin >> speed;  //reads the value entered by user

 if(speed < 20 || speed> 70)  

// if value of speed entered by user is outside the given range

 {

   speed = 0;  // speed is set to 0

 } }

Explanation:

In order to check how this function works you can write a main function and print the value of speed as following:

int main()

{ int speed;

   getSpeed(speed); //calls getSpeed function

   cout<<"speed is "<<speed; } //displays value of speed

Output:

Enter a number in the range of 20 through 70: 50

speed is 50

Output for if condition:

Enter a number in the range of 20 through 70: 80

speed is 0

You might be interested in
Write a program whose input is a string which contains a character and a phrase, and whose output indicates the number of times
shusha [124]

Answer:

The program in Python is as follows:

print("Enter a character followed by a phrase",end='')

word = input(": ")

char = word[0]

print("Occurrence: "+str((word.count(char))-1))

Explanation:

The prints an instruction to the user on how to input to the system

print("Enter a character followed by a phrase",end='')

This prompts and gets the user for input

word = input(": ")

This extracts the character from the input string

char = word[0]

This counts and prints the number of occurrence of the extracted character

print("Occurrence: "+str((word.count(char))-1))

6 0
3 years ago
The ________ of the operating system enables the user to communicate with the computer system. Select one:
mojhsa [17]
The user interface (correct answer is a)
8 0
3 years ago
In a bubble sort, you use a(n) ____ loop to make pair comparisons.
GarryVolchara [31]
In a bubble sort, you use an inner loop to make pair comparisons.
5 0
3 years ago
PLEASE HELP ME WITH THIS QUESTION:
Darina [25.2K]
There’s literally no question here
5 0
3 years ago
It is ok to sell services on Xbox in exchange for real-world money
Sati [7]
Is this a true or false question? If it is let me know and I can help! (:
6 0
4 years ago
Read 2 more answers
Other questions:
  • When using the strcat function, you must be careful not to overwrite the bounds of an array?
    5·1 answer
  • What are the five resources paid for by local taxes
    15·1 answer
  • Which Call of Duty game is the best?
    6·1 answer
  • Which best describes the Help feature of Word?
    13·2 answers
  • Universal Containers requires that all users add at least one Product Option from the Maintenance Feature to a bundle.
    5·1 answer
  • How to shutdow computer
    7·1 answer
  • You defined the raft class as shown.
    10·1 answer
  • The Klez virus was a worm created to "spoof others. What is "spoofing"?
    6·1 answer
  • What is the difference between a threat and an attack?
    7·1 answer
  • Identify the calculation performed by the following code.
    7·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!