#include <iostream>
#include <cmath>  // appropriate c++ libraries for functions & constants needed
#include <fstream>
#include <stdlib.h>

using namespace std;

const int N = 1000;
const double pi = 3.14159265; //constants applied

int main()
{

double num, factor, avg = 1.0;   //variables declared and initialised
int i;

num = N - 1;
factor = (N - 1) / N;


for(i=2;i<=N;i++)  //loop initiated and calculation
{
avg = avg + factor;
factor = factor * (N - i) / N;
}


cout << "Approximately, the average number of random songs played before a repeat song is "
<< (sqrt(pi * N / 2.0) - 1.0 / 3.0 + sqrt(pi / (2.0 * N)) / 12.0 - 4.0 / (135.0 * N)) << endl; //output message on the command prompt and tabulated answer to the formula/equation

{ 
ofstream out("Z:\mp3.txt"); 
if(!out) {              //output in command DOS being transferred to 
cout << "Cannot open file.\n";    // to the 'Notepad' programme


return 1; 
} 

out << "Answer is:" << (sqrt(pi * N / 2.0) - 1.0 / 3.0 + sqrt(pi / (2.0 * N)) / 12.0 - 4.0 / (135.0 * N)) << endl;
out.close(); 

system("Notepad.exe Z:\mp3.txt") ;   // ‘Notepad’ programme opens with answer saved to a created ‘mp3’.txt

return 0; 
}

}

List the functions used and their parameter lists
List key variables used in each function and their interpretation

doin a few exercises out of a text book of mine, and these two Q's are included, just want a bit of help on them.
would i be right in saying functuions here is only the int main () or is the loop a function as well?

main is a function, the loop isn't, but you are CALLING functions linke "sqrt" and "system". I'm guessing that's what they mean.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.