Code:
#include <stdio.h>
#include <conio.h>
#include <process.h>
#include "util.h"
int numDays1(float stock1[],float stock2[],int); /*function prototype*/
int numDays2(float stock2[],float stock1[],int); /*function prototype*/
int numSame(float stock1[],float stock2[],int); /*function prototype*/
int numAvg1(float stock1[],int); /*function prototype*/
int numAvg2(float stock2[],int); /*function prototype*/
float movAvg1(float stock1[],int); /*function prototype*/
int main()
{
system("CLS"); /*Clears the screen*/
printf("Report 1\n");
float stock1[]={34.25,40.50,36.50,40.00,
30.25,30.25,35.50,36.00,
34.25,37.00,34.00,35.00, /*Arrays are declared and initialized*/
36.25,34.25,40.50,41.50,
41.50,40.00,36.50,34.50};
float stock2[]={40.25,38.50,34.50,33.50,
30.50,29.75,37.50,38.00,
34.75,38.00,34.25,37.00,
34.25,37.50,34.50,38.50,
37.50,37.25,38.25,37.50};
printf("\nStock1 has exceeded the price of stock2 by: %d days\n",numDays1(stock1,stock2,20));
printf("\nStock2 has exceeded the price of stock1 by: %d days\n",numDays2(stock2,stock1,20));
printf("\nThe number of days in which the price of the stocks were the same: %d days\n\n",numSame(stock1,stock2,20));
PauseScreen();
system("CLS");
printf("Report 2\n");
printf("\nThe number of days in which stock1 exceeded it's price is: %d days\n", numAvg1(stock1,20));
printf("\nThe number of days in which stock2 exceeded it's price is: %d days\n", numAvg2(stock2,20));
PauseScreen();
system("CLS");
printf("Report 3\n");
printf("\nThe average for prices 1 through 5 are: %.2f\n", movAvg1(stock1,20));
getch();
return 0;
}
int numDays1(float stock1[],float stock2[],int size)
{
int index;
int days;
days;
days=0;
for (index = 0;index < size;index++)
if (stock1[index] > stock2[index])
{
days++;
}
return days;
}
int numDays2(float stock2[],float stock1[],int size)
{
int index;
int days;
days=0;
for (index = 0;index < size;index++)
if (stock2[index] > stock1[index])
{
days++;
}
return days;
}
int numSame(float stock1[],float stock2[],int size)
{
int index;
int days;
days=0;
for (index = 0;index < size;index++)
if (stock1[index] == stock2[index])
{
days++;
}
return days;
}
int numAvg1(float stock1[],int size)
{
float sum;
sum=0;
int index;
int days;
days=0;
int avg;
avg=0;
for (index = 0;index < size;index++)
{
sum=sum+stock1[index];
}
avg=(int)sum/size;
for (index = 0;index < size;index++)
if (stock1[index]> avg)
{
days++;
}
return days;
}
int numAvg2(float stock2[],int size)
{
float sum;
sum=0;
int index;
int days;
days=0;
int avg;
avg=0;
for (index = 0;index < size;index++)
{
sum=sum+stock2[index];
}
avg=(int)sum/size;
for (index = 0;index < size;index++)
if (stock2[index]> avg)
{
days++;
}
return days;
}
float movAvg1(float stock1[],int)
{
float sum;
sum=0;
int index;
int days;
days=0;
float avg;
avg=0.0;
for (index=0;index<5;index++)
{
sum=sum+stock1[index];
avg=sum/5;
}
return avg;
}
The float movAvg1 will be the function that will find the 16 5-day moving average. I plan on having another function called float movAvg2 to create the 16 5-day moving average for stock2. I appreciate any help.....Thanks....Tommy