Fill in the code to include any necessary headers and names

// Fill in the code to include any necessary headers and namespaces #include #include #include using namespace std; // Fill in the code that defines the prototype for the function factorial (see below) double factorial(int) int main) // Fill in the code to define integer variable called flavors int flavors; // Fill in the code that prompts the user to enter the number of ice-cream flavors (see example 1) cout

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

 // Fill in the code to include any necessary headers and namespaces #include #include #include using namespace std; // Fill in the code that defines the protot
 // Fill in the code to include any necessary headers and namespaces #include #include #include using namespace std; // Fill in the code that defines the protot

Get Help Now

Submit a Take Down Notice

Tutor
Tutor: Dr Jack
Most rated tutor on our site