Thread: Arrays With Stock Prices!

  1. #1
    Registered User
    Join Date
    Apr 2007
    Posts
    133

    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);
    
    }
    Last edited by GCNDoug; 04-19-2007 at 09:45 AM.

  2. #2
    Fear the Reaper...
    Join Date
    Aug 2005
    Location
    Toronto, Ontario, Canada
    Posts
    625
    Seems fine to me, except that secondGreater(stock1, stock2) is equivalent to firstGreater(stock2,stock1)
    Teacher: "You connect with Internet Explorer, but what is your browser? You know, Yahoo, Webcrawler...?" It's great to see the educational system moving in the right direction

  3. #3
    Registered User
    Join Date
    Apr 2007
    Posts
    133
    Is that going to cause an issue it seems to be working fine for me... lol

  4. #4
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    39,659
    Well it seems OK so far - does it work?

    It's a little over spaced vertically (too many blank lines) for my taste.
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.

  5. #5
    Fear the Reaper...
    Join Date
    Aug 2005
    Location
    Toronto, Ontario, Canada
    Posts
    625
    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.
    Teacher: "You connect with Internet Explorer, but what is your browser? You know, Yahoo, Webcrawler...?" It's great to see the educational system moving in the right direction

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Retail Outlet Managment System - the 4th
    By Presidentofusa in forum C Programming
    Replies: 3
    Last Post: 11-10-2007, 10:44 PM
  2. Moving Average Question
    By GCNDoug in forum C Programming
    Replies: 4
    Last Post: 04-23-2007, 11:05 PM
  3. Need Help With 3 Parallel Arrays Selction Sort
    By slickwilly440 in forum C++ Programming
    Replies: 4
    Last Post: 11-19-2005, 10:47 PM
  4. I have a function and I need multiple averages returned
    By tommy69 in forum C++ Programming
    Replies: 20
    Last Post: 04-13-2004, 11:45 AM
  5. Crazy memory problem with arrays
    By fusikon in forum C++ Programming
    Replies: 9
    Last Post: 01-15-2003, 09:24 PM