Hi everyone
I am trying to get done the stocks program
the first function is readStocks, it compiles but deosnt give me rigth ptompt, i guess i have some kind of execution error.
Could any one give me advice on that?
THank you.
//Stock's statistic
#include <iostream>
#include <stdlib.h>
#include <fstream>
using namespace std;
const int MAXSTOCKS = 5;
const int NUMDAYS = 5;
ifstream infile;
ofstream outfile;
void printHeader(void);
void readStocks(double [][NUMDAYS], string[], int & );
//void findStockAvg(double [][NUMDAYS], double[], int );
//void printStocks(double [][NUMDAYS], double[], string[], int );
//void findDayAvg(double [][NUMDAYS], double [], int );
//void printDayAvg(double [], int);
//void findMinDayOfStock(double[][NUMDAYS], string[], int);
//void findStockOfDay(double [][NUMDAYS], string [], int);
int main()
{
double stocks[MAXSTOCKS][NUMDAYS];
string stockName[MAXSTOCKS];
double stockAvg[MAXSTOCKS];
double dayAvg[MAXSTOCKS];
int numStocks;
infile.open("C:\\Documents and Settings\\Admin\\Desktop\\job_study\\college\\C++Home\\Stocks_1.txt");
//outfile.open("C:\Documents and Settings\Admin\Desktop\job_study\college\C++Home\Stocks_Report.txt");
outfile.open("con");
outfile.setf(ios::fixed, ios::floatfield);
printHeader();
readStocks( stocks, stockName, numStocks);
//findStockAvg(stocks, stockAvg, numStocks);
//printStocks(stocks, stockAvg, stockName, numStocks);
//findDayAvg(stocks, dayAvg,numStocks);
//printDayAvg(dayAvg, numStocks);
//findMinDayOfStock(stocks, stockName, numStocks);
//findStockOfDay(stocks, stockName, numStocks);
system("pause");
infile.close();
outfile.close();
return 0;
}
void printHeader(void)
{
outfile <<" Anton Deinega CIS 1.5 EMY6 Program 4 Due: November 20, 2006"<< endl;
outfile <<"--------------------------------------------------------------------"<<endl;
outfile <<"\t\t\tStock Prices"<<endl<<endl;
outfile.precision(2);
outfile.setf(ios::right);
outfile<<" Stocks";
outfile.width(10);
outfile<<"Day 1";
outfile.width(10);
outfile<<"Day 2";
outfile.width(10);
outfile<<"Day 3";
outfile.width(10);
outfile<<"Day 4";
outfile.width(10);
outfile<<"Day 5";
outfile.width(10);
outfile<<"Average"<<endl;
outfile <<"--------------------------------------------------------------------"<<endl;
return;
}
void readStocks(double stocks[][NUMDAYS], string stockName[], int & numStocks )
{
int numStocks =0;
while (!cin.eof())
{
infile>> stockName[numStocks];
for (int i=0; i<NUMDAYS;i++)
infile>>stocks[numStocks][i];
numStocks++;
}
return;
}
/*
void findStockAvg(double stocks[][NUMDAYS], double stockAvg[], int numStocks)
{
double sum;
double StockAvg;
for (int stockNum = 1; stockNum < NUMDAYS; stockNum++)
{
sum = 0;
for (int dayNum = 1; dayNum < stockAvg[MAXSTOCKS]; dayNum++)
{
sum += stocks[stockNum][dayNum];
StockAvg = (double)sum/numStocks;
}
}
return;
}
/*
void printStocks(double stocks[][NUMDAYS], double stockAvg[], string stockName[], int numStocks)
{
//ofstream outfile("C:\Documents and Settings\Admin\Desktop\job_study\college\C++Home\StockReport.txt");
ofstream outfile("con");
outfile.setf(ios::fixed,ios::floatfield);
outfile.precision(2);
outfile.setf(ios::right);
outfile.width(10);
for (int stockNum = 0; stockNum < numStocks; stockNum++ )
{
outfile << stockName[stockNum] << " ";
for (int dayNum = 0; dayNum < NUMDAYS; dayNum++)
{
outfile << stocks[stockNum][dayNum] << " ";
}
outfile << endl;
}
return;
}
/* void findDayAvg(double stocks[][NUMDAYS], double DayAvg[], int numStocks)
{
double sum;
double DayAvg;
for (int stockNum = 1; stockNum < NUMDAYS; stockNum++)
{
sum = 0;
for (int dayNum = 1; dayNum < MAXSTOCKS; dayNum++)
sum += stocks[stockNum][dayNum];
DayAvg = (double)sum/numStocks;
}
return;
}
*/
/* void printDayAvg(double dayAvg[], int numStocks)
{
//ofstream outfile("C:\Documents and Settings\Admin\Desktop\job_study\college\C++Home\StockReport.txt");
ofstream outfile("con");
outfile<<"------------------------------------------------------------------------------"<<endl;
outfile<<"Day Avg";
for (int stockNum = 1; stockNum < NUMDAYS; stockNum++)
{
outfile<<dayAvg[numStocks]<<endl;
}
outfile.setf(ios::fixed,ios::floatfield);
outfile.precision(2);
outfile.setf(ios::right);
outfile.width(10);
return;
}
/*
void findMinDayOfStock(double stocks[][NUMDAYS], string stockName[], int numStocks)
{
int smallest, dayNum;
for (int dayNum = 1; dayNum < NUMDAYS; dayNum++)
cout<<stockName[0]<<" had its smallest value on day "<< day <<" with a value of "<< smallest<<endl;
cout<<stockName[1]<<" had its smallest value on day "<< day <<" with a value of "<< smallest<<endl;
cout<<stockName[2]<<" had its smallest value on day "<< day <<" with a value of "<< smallest<<endl;
cout<<stockName[3]<<" had its smallest value on day "<< day <<" with a value of "<< smallest<<endl;
return;
}
/*
void findStockOfDay(double stocks [][NUMDAYS], string stockName[], int numStocks)
{
int smallest, day;
for (int dayNum = 1; dayNum < NUMDAYS; dayNum++)
cout<<"On day "<<day<<" C was the stock with the smallest value which was "<<smallest<<endl;
cout<<"On day "<<day<<" C was the stock with the smallest value which was "<<smallest<<endl;
cout<<"On day "<<day<<" C was the stock with the smallest value which was "<<smallest<<endl;
cout<<"On day "<<day<<" MSFT was the stock with the smallest value which was "<<smallest<<endl;
return;
}
*/