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
GalinKa [24]
3 years ago
7

Write a code in C++ that can save 100 random numbers in an array that are between 500 and 1000. You have to find the average of

the 100 random numbers. To find the average of the numbers, you have to use a functions. You are not allowed to use return, cin or cout statements in the functions.
Hint : you have to use function call by reference.
Computers and Technology
1 answer:
Anni [7]3 years ago
3 0

Answer:

#include <iostream>

#include <random>

//here we are passing our array and a int by ref

//to our function called calculateAverage

//void is infront because we are not returning anything back

void calculateAverage(int (&ar)[100], int &average){

 int sum = 0;

 for(int i = 0;i < 100; i++){

   //adding sum

   sum += ar[i];

 }

 //std:: cout << "\naverage \t\t" << average;

//calculating average here

 average += sum/100;

}

int main() {

 int value = 0;

 int average = 0;//need this to calculate the average

 int ar[100];

 //assign random numbers from 500 to 1000

 //to our array thats called ar

 for(int i = 0; i < 100; i++){

   value = rand() % 500 + 500;

   ar[i] = value;

   

 }

 calculateAverage(ar,average);

 // std:: cout << "\naverage should be \t" << average;

 

}

Explanation:

not sure how else this would work without having to pass another variable into the function but I hope this helps!

I commented out the couts because you cant use them according to ur prof but I encourage you to cout to make sure it does indeed calculate the average!

You might be interested in
Dell Computer purchases parts and resources for its computers from multiple suppliers that are spread across the world. This pra
givi [52]
The correct answer is outsourcing
6 0
3 years ago
We can see spreadsheet results graphically by creating:
Inessa [10]
Please ask a question.
5 0
3 years ago
Given a sorted list of integers, output the middle integer. A negative number indicates the end of the input (the negative numbe
masya89 [10]

Answer:

The program in Python is as follows:

myList = []

num = int(input())

count = 0

while num>=0:

   myList.append(num)

   count+=1

   num = int(input())

myList.sort()

mid = int((count-1)/2)

print(myList[mid])

Explanation:

This initializes the list

myList = []

This gets the first input

num = int(input())

This initializes count to 0

count = 0

The following is repeated until the user inputs a negative number

while num>=0:

This appends the input number to the list

   myList.append(num)

This increments count by 1

   count+=1

This gets another input

   num = int(input())

This sorts the list

myList.sort()

Assume the number of inputs is odd, the middle element is calculated as

mid = int((count-1)/2)

This prints the middle element

print(myList[mid])

<em>From the complete question. the condition that ends the loop is a negative integer input</em>

8 0
3 years ago
Holi alguien sabe como cambiar el gamertag en XBox App (para iOS)?
Schach [20]

Answer:

Hola, cambiar tu gamertag (el nombre o apodo que te identifica en los juegos de XBox en línea) es muy sencillo. Simplemente debes ingresar al menú principal de tu aplicación XBox App, y una vez allí seleccionar la imagen que te identifica como usuario. Al clickear allí, podrás seleccionar la opción Personalizar, donde se desplegará un menú de opciones dentro de las cuales se encontrará la de cambiar tu gamertag o nombre de usuario. Recuerda que solo podrás cambiar tu gamertag en forma gratuita una única vez.

3 0
3 years ago
I wish we could visit Paris for the holidays into exclamatory​
shusha [124]

Answer:

wdym

Explanation:

3 0
3 years ago
Read 2 more answers
Other questions:
  • Two electronics students are discussing static electricity and electric current. Student A says that a basic property of static
    12·1 answer
  • . What may happen if a large number of computer users are attempting to access a Web site at the same
    10·2 answers
  • Among the web programming languages, css is used to define _____ of the web page
    5·1 answer
  • These items describe guidelines for the effective use of presentation graphics. Graphics should be large enough to be seen by th
    9·1 answer
  • In 4-bit sign magnitude representation, what is the binary encoding of the number -5?
    15·1 answer
  • Does clicking ads and pop ups like the one shown in this image could expose your computer to malware?
    15·1 answer
  • A system is composed of four parts, J, K, L, and M. All four must function for the system to function. The four component reliab
    6·1 answer
  • 9
    10·1 answer
  • Suppose you are choosing between four different desktop computers: one is Apple MacIntosh and the other three are PC-compatible
    15·1 answer
  • Assignment 4: Evens and Odds<br><br><br> How do I fix this?
    13·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!