Monday, May 24, 2010

Computer science C++ programing?

#include %26lt;iostream.h%26gt;


#include %26lt;stdlib.h%26gt;





using namespace std;





int getstockprices;


float printaverage;


float printlowest;


float printhighest;


int main()


{


float stockprice [31];


int min=0;


int max=0;


float avg=0;


float total=0;





for(int day = 0; day %26lt; 31; day++)


{


void get_stock_price(float %26amp;stockprice);


cout%26lt;%26lt; "Please enter the closing stock price for day"%26lt;%26lt;day+1%26lt;%26lt;":"%26lt;%26lt;endl;


cin%26gt;%26gt;stockprice [day];





if (stockprice [day] %26gt; max)


max=day;


if (stockprice [day] %26lt; min)


min=day;


else if (day == 0)


min=day;


total+= stockprice[day];





}


cout%26lt;%26lt; "highest Price :"%26lt;%26lt;stockprice[max] %26lt;%26lt; " on day: " %26lt;%26lt; max%26lt;%26lt;endl;


cout%26lt;%26lt; "Lowest Price :"%26lt;%26lt;stockprice[min]%26lt;%26lt; "on day; "%26lt;%26lt; min %26lt;%26lt;endl;


cout%26lt;%26lt; "Average Price:"%26lt;%26lt;total/31.0%26lt;%26lt;endl;


system("PAUSE");


return 0;


}


tells 31 days of stock prices, highest the day it occurs, lowest the day it occurs and the average. it compiles but i don't know how to do this in functions. How can i write it in functions.

Computer science C++ programing?
first question though why do use globals all processing is done inside the main anyway and what's the use of the getstockprices function. i can't see its definition in there.





anyway, you can have a function for getting the input and storing this in the day array. if you don't know how to use pointers then declare day array as a global.





then have another function for processing the input and checking max and min values. you can declare this as global as well





then have another function for displaying the results





and that's it. i could write the code but that will be cheating
Reply:You are joking, right?

hydrangea

No comments:

Post a Comment