Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

C programming: I am getting the following errors in my program. Would someone kindly review my errors and code and assist me in finding how

C programming: I am getting the following errors in my program. Would someone kindly review my errors and code and assist me in finding how to address it. I cannot use any fancy coding, this is a beginners course and we are limited to loops and maybe strings. Absolutely no pointers. Thank you so much.

Errors:

image text in transcribedimage text in transcribed

Code:

Three files; stocks.c, stats.c, and io.c:

stocks.c:

* stocks.c

* program is for input stock price using a for looping construct

*

*

* gcc -o stocks.x stocks.c

* ./stocks.x

*

*/

#include

#include

#include

#include "io.h"

#include "stats.h"

int main()

{

int size = 0;

float median = 0.0f,

mean = 0.0f,

variance = 0.0f,

max = 0.0f,

min = 0.0f;

float array[size],

data[size];

char set = 'n',

order;

// print greeting

print_greeting();

//ask user number of stocks being analyzed

printf("How many stocks you want to analyze? ");

scanf("%d",&size);

//read data one at a time

read_data(array,size);

//Ask user if they want to sort the prices

printf("Do you want to sort the prices? (Y/N)");

scanf("%c", &set);

if(set == 'y' || set == 'Y')

{

printf("Do you want to sort the prices in ascending, ");

printf("or descending order? (Type A/D) ");

scanf("%c", &order);

if(order == 'y' || order == 'Y')

sort(array, data, size, 'a');

else if(order == 'n' || order == 'N')

sort(array, data, size, 'd');

}

//compute mean,median,min,max,variance;

mean = get_average(data, size);

median = get_median(data, size);

min = get_min(data, size);

max = get_max(data, size);

variance = get_variance(data, size);

//print computed value

print_results(data, size, mean, median, min, max, variance);

return 0;

}

stats.c:

/*

* stats.c

*/

#include

#include "stats.h"

float get_average(const float data[],const int size)

{

int i = 0;

float sum=0.0f,

avg=0.0f;

for(i = 0; i

sum += data[i];

//average = sum of stocks/size of the array

avg = sum/ size;

return avg;

}

float get_variance(const float data[],const int size, float mean)

{

int i = 0;

float var = 0.0f,

temp = 0.0f;

for(i = 0; i

//the sum of the mean squared

temp += data[i] * data[i];

//is th varianceum of stocks - mean squared

var = temp / size - mean * mean;

return var;

}

float get_max(const float data[], const int size)

{

int i;

float max = data[i];

for( i = 1;i

{

if(data[i] > max)

max = data[i];

}

return max;

}

float get_min(const float data[],const int size)

{

int i;

float min = data[i];

for( i = 1;i

{

if(data[i]

min = data[i];

}

return min;

}

void sort(const float input[], float output[],const int size,const char order)

{

int i,

j = 0.0f;

if(order =='a' || order=='A')

{

for( i = 0; i

{

output[i] = input[i];

for( j = i+1;j

{

if(input[i] > input[j])

{

output[i] = input[j];

}

}

}

}

else if(order == 'd'||order == 'D')

{

for( i = 0; i

{

output[i] = input[i];

for(j = i+1; j

{

if(input[i]

{

output[i] = input[j];

}

}

}

}

}

float get_median(const float input[],const int size)

{

float med = 0.0f;

if(size % 2 == 0)

med = (input[size /2] + input[(size /2) - 1])/ 2.0;

else

med = input [size/2];

return med;

}

io.h:

* this is the io.c file * * */ #include #include "io.h"

void read_data( float array[],const int size) { int i; printf("Please enter stock price(s) %d stock value separated by space ",size); for( i=0; i stocks.c: In function 'main': stocks.c: 85:14: error: too few arguments to function 'get_variance' variance get-variance (data, size); = In file included from stocks.c:18:0: stats.h: 13:7: note: declared here float get_variance (const float datall, const int size, float mean): Compilation failed

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Database Systems A Practical Approach To Design Implementation And Management

Authors: THOMAS CONNOLLY

6th Edition

9353438918, 978-9353438913

Students also viewed these Databases questions

Question

Explain the function and purpose of the Job Level Table.

Answered: 1 week ago