Code:
//Doug Miller
//Project #4 - Working with stock information and organizing them.
#include <stdio.h>
#include <conio.h>
#include "util.h"
#define MAX_STOCKS 20
float stock1[MAX_STOCKS] =
{34.25,40.50,36.50,40.00,
30.25,30.25,35.50,36.00,
34.25,37.00,34.00,35.00,
36.25,34.25,40.50,41.50,
41.50,40.00,36.50,34.50};
float stock2[MAX_STOCKS] =
{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};
//Report 1 Functions
int first_Greater (float stock1[], float stock2[]);
int second_Greater (float stock1[], float stock2[]);
int same_Price (float stock1[], float stock2[]);
void print_Report1(int first_Greater, int second_Greater, int same_Price);
//END OF REPORT 1 FUNCTIONS
int main()
{
int first_Greater_C = 0;
int second_Greater_C = 0;
int same_C = 0;
//print title
PrintTitle();
//printDate
PrintDate();
//Find first_Greater
first_Greater_C = first_Greater(stock1, stock2);
//Find second_Greater;
second_Greater_C = second_Greater(stock1, stock2);
//Fine same
same_C = same_Price(stock1, stock2);
//print report 1
print_Report1(first_Greater_C, second_Greater_C, same_C);
//END OF REPORT 1
//pause screen
PauseScreen();
// Declare Variables
_getch();
return 0;
}
int first_Greater (float stock1[], float stock2[])
{
int i = 0;
int f_Greater_Count = 0;
for (i = 0; i < MAX_STOCKS; i++)
{
if (stock1[i] > stock2[i])
{
f_Greater_Count = f_Greater_Count + 1;
}
}
return f_Greater_Count;
}
int second_Greater (float stock1[], float stock2[])
{
int i = 0;
int s_Greater_Count = 0;
for (i = 0; i < MAX_STOCKS; i++)
{
if (stock1[i] < stock2[i])
{
s_Greater_Count = s_Greater_Count + 1;
}
}
return s_Greater_Count;
}
int same_Price (float stock1[], float stock2[])
{
int i = 0;
int same_Count = 0;
for (i = 0; i < MAX_STOCKS; i++)
{
if (stock1[i] == stock2[i])
{
same_Count = same_Count + 1;
}
}
return same_Count;
}
void print_Report1(int first_Greater, int second_Greater, int same_Price)
{
printf("The amount of days stock one is greater is: %d\n\n", first_Greater);
printf("The amount of days the stock two is greater is: %d\n\n", second_Greater);
printf("The amount of days the stocks are the same is: %d\n\n", same_Price);
}