Two questions. The first one is that the program can run, but it cannot show the result. The second one shows the error.

Program 1 needs to create an array to save the number of students(column) and the number of exams(row). The Program 1 needs to calculate the student's average and class average. Create and call a function that calculates the exam averages for each student and place them in an additional column(the column could already be there waiting for this function). This function shold also cout/rpint all of the averages to the screen. Back in the main, cout the class average (1 number).

Program 1 Code
#include <iostream>
#include <stdio.h>
#include <stdlib.h>

void readgrade();
void average();
void classaverage();
using namespace std;
void readgrade()
{
int m,n; //m means exam numbers, n means student numbers
int i,j;
float score[n][m];
cout << "How many students " << endl;
cin >> n;
for (i = 0; i < n; i++) // Input data
{
cout << "How many exam numbers "<< endl;
cin >> m;
cout << "Input Student " << i+1 << "'s No. "<< m <<" grade" << endl;
for(j = 0; j < m; j++)
cin >> score[i][j];
}
}
void average()
{
int i, j, m, n;
float score[n][m+1];
float s;
readgrade();
for(i = 0; i < n; i++) //calculate average
{
for(j = 0; j < m; j++)
s = 0.0;
s = s + score[i][j];
score[n][m+1]=s / (n+1);
cout << "No. " << i+1 << " Student's Average: " << score[n][m+1] << endl;
}
}

void classaverage()
{
int i,j,m,n;
double avg_stu, avg_class, sum_student,sum_class;
float score[n][m+1];
readgrade();
for(i = 0; i < n; i++) //calculate average
{
for(j = 0; j < m; j++)
sum_student = 0.0;
sum_student = sum_student + score[i][j];
score[n][m+1] = sum_student / (n+1);
avg_stu=score[n][m+1];
}
sum_class+= avg_stu;
avg_class = (avg_stu) / i;
cout << "Class Average: " << avg_class << endl;
}

int main()
{
readgrade();
average();
classaverage();
return 0;
}

Program 2 is to calculate the Black Scholes model
#include <iostream>
#include <math.h>
#include <stdlib.h>
#include <stdio.h>
using namespace std;
double N(double);
double d1(double,double,double,double);
double d2(double,double,double,double,double);
double C(double,double,double,double,double);
double P(float,float,float,float,float);

double N(double z)
{
return (erf(z/sqrt(2.)))/2. - (erf(-INFINITY/sqrt(2.0))) / 2.;
}

double d1(double S0, double k, double r, double sigma, double T)
{
return log(S0 / k) + ((r + pow(sigma,2) / 2) * T) / (sigma * sqrt(T));
}

double d2(double S0, double k, double r, double sigma, double T)
{
return (log(S0 / k) + ((r + pow(sigma,2) / 2) * T) / (sigma * sqrt(T))) - (sigma * sqrt (T));
}

double C(double S0, double k, double r, double sigma, double T)
{
return S0 * N(d1) - k * exp((-1.0) * r * T) * N(d2);
}

double P(double S0, double k, double r, double sigma, double T)
{
return ((-1.0) * S0 * N((-1.0) * d1)) + k * exp((-1.0) * r * T) * N((-1.0) * d2);
}

int main()
{ double s, x, rate, sig, time;
cout << "Input Spot Price: " << endl;
cin >> s;
cout << "Input Exercise Price: " << endl;
cin >> x;
cout << "Input Interest rate: " << endl;
cin >> rate;
cout << "Input Volatility: " << endl;
cin >> sig;
cout << "Time to Maturity: " << endl;
cin >> time;
cout << "Call Opion Price: " << C(s, x, rate, sig, time) << endl;
cout << "Put Option Price: " << P(s, x, rate, sig, time) << endl;
Can you post the code in the format style. There is a button on the right side with two arrows. For instance post it like this post it like this. It is much easier for us to detect the problem
I read this quickly so apologize if I didnt catch your problem. Meanwhile, if you didn't write it, can you tell what your peoblem is in the code.
Topic archived. No new replies allowed.