We're a community of 1.1M IT Pros here for help, advice, solutions, professional growth and fun. Join us!
1,080,307 Members — Technology Publication meets Social Media

# write up questions

``````#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();

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?

2
Contributors
1
2 Hours
Discussion Span
1 Year Ago
Last Updated
2
Views
pjh-10
Junior Poster in Training
71 posts since Feb 2012
Reputation Points: 10
Skill Endorsements: 0

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.

VernonDozier
Posting Expert
5,675 posts since Jan 2008
Reputation Points: 2,633