# Arrays With Stock Prices!

This is a discussion on Arrays With Stock Prices! within the C Programming forums, part of the General Programming Boards category; Hi I'm still a little uncertain with all my arrays and functions so I was wondering if before I went ...

1. ## Arrays With Stock Prices!

Hi I'm still a little uncertain with all my arrays and functions so I was wondering if before I went any furture with this project if you guys could tell me if I'm going the right direction.

P.S. Sorry about all the questions I have a massive project due for the next three weeks lol.

This is only the very beginning of this project so if you could could just give me some tips/advice i'd really appreciate it. Thanks!

This code is for the first report I must do... out of four lol. Here the question then my code as of now.

I. The Analysis
Report 1

Write functions to do the following:

Determine the number of days on which the price of the first stock exceeded the price of the second stock.

Determine the number of days on which the price of the second stock exceeded the price of the first stock.

Determine the number of days on which the price of the stocks was the same.

Display the results with appropriate labels.

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: &#37;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);

}```

2. Seems fine to me, except that secondGreater(stock1, stock2) is equivalent to firstGreater(stock2,stock1)

3. Is that going to cause an issue it seems to be working fine for me... lol

4. Well it seems OK so far - does it work?

It's a little over spaced vertically (too many blank lines) for my taste.

5. It won't cause an issue...but the reason you write functions is to modularize your program and prevent you from re-writing code...so if you're okay with writing all the needless code, then it's fine.