Question

In: Computer Science

what is the calculated the average code using C++ Having a hard time trying to get...

what is the calculated the average code using C++

Having a hard time trying to get the float average.

Solutions

Expert Solution

CODE:

#include<iostream>
using namespace std;
int main()
{
//array of float values for which we need to calculate the average.
float array1[6]={10.0,20.5,13.7,14.3,19.7,25.3};
int i;//loop variable.
float sum=0.0;//variable to the sum of the elements.
cout<<"The array elements are : ";
//loop to calculate the sum of the values of the array.
for(i=0;i<6;i++)
{
cout<<array1[i]<<" ";
sum=sum+array1[i];
}
float average;//a float variable to store the float average.
//we know average is sum of elements divided by number of elements.
//here the sum of elements is stored in sum variable.
//and we know there are 6 elements.
average=sum/6;//calculating average.
//printing the average.
cout<<endl<<"The float average of elements is "<<average<<endl;
}

CODE ATTACHMENTS:

OUTPUT:

I have took a float elements array.Then calculated the sum using a loop.

Then calculated the average of the elements.

Please do comment for any queries.
PLease like it.
Thank You.


Related Solutions

I'm having a very hard time getting this c++ code to work. I have attached my...
I'm having a very hard time getting this c++ code to work. I have attached my code and the instructions. CODE: #include using namespace std; void printWelcome(string movieName, string rating, int startHour, int startMinute, char ampm); //menu function //constants const double TICKET_PRICE = 9.95; const double TAX_RATE = 0.095; const bool AVAILABLE = true; const bool UNAVAILABLE = false; int subTotal,taxAdded, totalCost; // bool checkAvailability( int tickets, int& seatingLeft){ //checks ticket availability while(tickets > 0 || tickets <= 200) //valid...
C# programming. Comment/Explain the below code line by line. I am having a hard time following...
C# programming. Comment/Explain the below code line by line. I am having a hard time following it. using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; namespace Nth_prime {     class Program     {         public static bool isPrime(int number)         {             int counter = 0;             for (int j = 2; j < number; j++)             {                 if (number % j == 0)                 {                     counter = 1;                     break;                 }             }             if (counter == 0)             {                 return true;             }             else             {                 return false;             }         }...
In C++ and input code using the template below Get a copy of the caseswitch.cpp. The...
In C++ and input code using the template below Get a copy of the caseswitch.cpp. The purpose of the program is to demonstrate how to use Switch statement. Complete the for loop so that the program will ask the user for 6 input grades. Compile and run this C++ program. Use input value A, B, C, D, E, and F. Notice there is no output for B and E. Add cases for them. B is "Good Work." Add a case...
Explain to me what Switcheo ICO is about? I’m having a hard time to understand what...
Explain to me what Switcheo ICO is about? I’m having a hard time to understand what their product or service is? All about networks stuff I just don’t get it Please help me understand it
A surgeon is having difficulty trying to get a Steinmann pin to fit in a treatment...
A surgeon is having difficulty trying to get a Steinmann pin to fit in a treatment for a tibial fracture. In a last ditch effort to finish the operation, he bends the pin to make it go in. What corrosion problems might this cause?
Hello, I'm having a hard time solving these problems because I have no idea on what...
Hello, I'm having a hard time solving these problems because I have no idea on what to do with accrued interest. Help is highly appreciated! On March 1, 2015, Bowan Corporation issued 6% bonds dated February 1, 2015, the face amount of $700,000. The bonds were sold for the present value of the bonds on March 1, 2015 plus one-month accrued interest. The bonds mature on January 31, 2018. Interest is paid semiannually on July 31 and January 31. Bowan's...
can someone explain to me what osmolality is.? i am having a hard time understanding it
can someone explain to me what osmolality is.? i am having a hard time understanding it
Having a really hard time with this question! To fit a contact lens to a patient's...
Having a really hard time with this question! To fit a contact lens to a patient's eye, a keratometer can be used to measure the curvature of the cornea-the front surface of the eye. This instrument places an illuminated object of known size at a known distance p from the cornea, which then reflects some light from the object, forming an image of it. The magnification M of the image is measured by using a small viewing telescope that allows...
I'm having trouble with my do while loop. I'm trying to get it where if the...
I'm having trouble with my do while loop. I'm trying to get it where if the user enter's 3 after whatever amount of caffeinated beverages they've entered before then the loop will close and the rest of my code would proceed to execute and calculate the average price of all the caffeinated beverages entered. Can someone please help me with this? Here's my Code: import java.util.Scanner; public class Main { public static void main(String[] args) { CaffeinatedBeverage[] inventory = new...
I'm having a hard time finding this equation: calculate the absolute uncertainty in the linear mass...
I'm having a hard time finding this equation: calculate the absolute uncertainty in the linear mass density ??
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT