Question: 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. Thank you so much.
ERROR MESSAGES
stocks.c:65:16: error: 'mean' undeclared (first use in this function) print_results(mean, average, min, max, variance); ^~~~ stocks.c:65:16: note: each undeclared identifier is reported only once for each function it appears in stocks.c:65:2: error: too few arguments to function 'print_results' print_results(mean, average, min, max, variance); ^~~~~~~~~~~~~ In file included from stocks.c:18:0: stats.h:21:6: note: declared here void print_results(const float array[], int size, float mean, float ^~~~~~~~~~~~~ stocks.c:25:8: warning: variable 'median' set but not used [-Wunused-but-set-variable] float median = 0.0f,
CODE:
stocks.c
#include
#include
#include
#include "io.h"
#include "stats.h"
int main()
{
int size = 0;
float median = 0.0f,
variance = 0.0f,
max = 0.0f,
min = 0.0f,
average = 0.0f;
float array[size],
data[size],
input[size];
char order;
//print greeting
print_greeting();
//ask user number of stocks being analyzed
printf("Enter the number of stocks we will be analyzing: ");
scanf("%d", &size);
//read data one at a time
read_data(array, size);
//Ask user if they want to sort their prices
printf("Do you want to sort the prices in ascending, ");
printf("or descending order? (A/D). ");
scanf("%c", &order);
//get the stats
average = get_average(data, size);
median = get_median(input, size);
variance = get_variance(data, size);
max = get_max(data, size);
min = get_min(data, size);
//print the results
print_results(mean, average, min, max, variance);
return 0;
}
io.c
#include
#include "io.h"
void sort(const float input[], float output[], const int size, const char order);
{
int i = 0,
j = 0;
float temp;
for(i = 0; i < size; i++)
output[i] = input[i];
for(i = 0; i = size - 2; i++)
{
for(j = i + 1; j <= size - 1; j++)
{
if(order == 'A')
{
if (output[i] > output[j])
{
temp = output[i];
output[i] = output[j];
output[j] = temp;
}
}
else if(order == 'D')
{
if(output[i] < output[j])
{
temp = output[i];
otput[i] = output[j];
output[j] temp;
}
}
}
}
}
void read_data(float array[], int size);
{
int i = 0;
printf("Please enter the stocks you wish to analyze: ");
for(i = 0; i < size; i++)
{
printf("Please enter the stock price #%d: ", i + 1);
scanf(%f", &array[i]);
}
}
void print_results(const float array[], int size, float mean,
float median, float min, float max, float variance);
{
printf("Mean = $%.2f ", mean);
printf("Median = $%.2f ", median);
printf("Min = $%.2f ", min);
printf("Max = $%.2f ", max);
printf("Variance = $%.2 ", variance);
}
void print_greeting();
{
printf(" This application will compute the statistics of and sort ");
printf("a series of stock prices. ");
}
io.h
void sort(const float input[], float output[], const int size, const char order); void read_data(float array[], int size); void print_results(const float array[], int size, float mean, float median, float min, float max, float variance); void print_greeting();
stats.c
#include
#include
#include "stats.h"
float get_average(const float data[], const int size)
{
int i = 0;
float sum = 0.0,
average = 0.0;
for (i = 0; i < size; i++)
sum += data[i];
average = sum/size
return average
}
stats.c
float get_average(const float data[], const int size); float get_variance(const float data[], const int size); float get_max(const float data[], const int size); float get_min(const float data[], const int size); void sort(const float input[], float output[], const int size, const char order); float get_median(const float input[], const int size); void read_data(float array[], int size); void print_results(const float array[], int size, float mean, float median, float min, float max, float variance); void print_greeting();
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
