Fill in the code to include any necessary headers and names
Solution
The GIVEN CODE WORKING PERFECTLY FOR THSI PROBLEM
CODE
#include <iostream>
#include<string>
#include<fstream>
using namespace std;
double factorial(int);
int main()
{
int flavors;
cout << \"How many ice-cream flavors?\" << endl;
cin >> flavors;
if(flavors<=0)
{
cout<<\"Error: number of flavors must be greater than zero\";
return 1;
}
string outputFile;
cout << \"Name of the output file: \";
cin >> outputFile;
ofstream dataOut(outputFile);
double nf = factorial(flavors);
for(int scoops = 1; scoops<=flavors;++scoops)
{
double kf = factorial(scoops);
double nkf = factorial(flavors-scoops);
int combinations = (int) (nf/(kf*nkf));
dataOut << scoops << \"\\t\" << combinations << \"\ \";
}
dataOut.close();
return 0;
}
double factorial(int x)
{
double f = 1;
for(int i =2;i<=x;++i)
{
f *=i;
}
return f;
}
COMMANDLINE OUTPUT
$./main How many ice-cream flavors? 31 Name of the output file: Myoutputfile
Myoutputfile
1 31
2 465
3 4495
4 31465
5 169911
6 736281
7 2629575
8 7888725
9 20160075
10 44352164
11 84672315
12 141120525
13 206253074
14 265182524
15 300540195
16 300540195
17 265182524
18 206253074
19 141120525
20 84672315
21 44352164
22 20160075
23 7888725
24 2629575
25 736281
26 169911
27 31465
28 4495
29 465
30 31
31 1

