Question: Can anyone help me with my c++ code. I am trying to make the output go to an output file. I am using xcode and

Can anyone help me with my c++ code. I am trying to make the output go to an output file. I am using xcode and cannot get it to work. Can someone edit my code so it will output to a file in xcode?

#include

#include

#include

using namespace std;

float readFloat()

{

float num;

cout<<"Enter the float value: ";

cin>>num;

return num;

}

void printFloat(float num)

{

cout<

}

float sum(float a, float b)

{

return a + b;

}

float avg(float a[], int size)

{

float s = 0;

for(int i = 0; i < size; i++)

s += a[i];

return s / size;

}

float difference(float a, float b)

{

return abs(a - b);

}

float power(float a, int b)

{

float result = 1;

for(int i = 1; i <= b; i++)

result *= a;

return result;

}

float larger(float a, float b)

{

if(a > b)

return a;

return b;

}

float smallest(float a, float b)

{

if(a < b)

return a;

return b;

}

int main()

{

ofstream outData;

float numbers[5];

for(int i = 0; i < 5; i++)

numbers[i] = readFloat();

for(int i = 0; i < 5; i++)

{

printFloat(numbers[i]);

cout<<" ";

}

cout<

float total = 0;

for(int i = 0; i < 5; i++)

total = sum(total, numbers[i]);

cout<<"The sum of given 5 numbers is: ";

printFloat(total);

cout<

cout<<"The average of given 5 numbers is: "<

cout<<"The difference between "<

cout<<"The difference between "<

cout<

cout<

float large = numbers[0];

for(int i = 1; i < 5; i++)

large = larger(large, numbers[i]);

cout<<"The largest of 5 numbers is: "<

float small = numbers[0];

for(int i = 1; i < 5; i++)

small = smallest(small, numbers[i]);

cout<<"The smallest of 5 numbers is: "<

cout<<"The average of the 4 largest values is: "<<(total - small) / 4<

cout<<"The average of the 4 smallest values is: "<<(total - large) / 4<

cout<<"The running total of five numbers is: ";

total = 0;

for(int i = 0; i < 5; i++)

{

total = sum(total, numbers[i]);

cout<

}

{

outData.open("Output.txt");

}

cout<

}

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!