Help with Transcendental Function Implementation Problem!! Code is written just need more input

I have been working on a c++ project for my computer science class, and this is my first class. I have a code written, but need help with my output. I have looked online and found a similar post from a few years ago, but it did not help me too much. Here is the description for what I am suppose to write, I have also attached my whole project specifications. I have also attached my code in which I have so far. Thanks for the help guys I really appreciate it.

Description: You are to write a C++ program in Visual Studio 2013 and link and run the program as a Win32 console application that computes the transcendental functions, sin(x) and e(x) [called sin(x) and exp(x) in <cmath>, respectively], for a given subset of a range of values of type double. The program should accept a range of values and an increment size from the user. The values of the given interval should be displayed along with the <cmath> sin(x) and exp(x) functions, your sin(x), and two versions of your exp(x) functions; the two versions of your exp(x) function. For the purpose of specification, the names of your functions will be called my_sin() and my_exp() so that they can be distinguished from the <cmath> ones. You need not know what these mean. Only follow the formulas below for your functions and use the <cmath> functions for comparison of correct values. As described in more detail below, you will output your results to a file.





1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
 #include <iostream>
#include <cmath>
#include <iomanip>
#include <fstream>
 
using namespace std;
 
double factorial(const int);
double my_pow(const double, const int);
long double my_sin(const double);
double my_exp(double);
double lower;
double upper;
double increment;
double y;
char answer;
 
int main()
{
 
       ofstream fout("output1.txt"); //if output.txt does not exist it is created
                                                //if it does exist the existing data is wiped out and a new set written to it
 
       do
       {
              cout << "Enter lower and upper bounds: ";  // lower and upper bound user inputs for intial start up
              cin >> lower >> upper;
              cout << "Enter increment: "; // incrementation of how the actual increments between the lower and upper bound number entered.
              cin >> increment;
 
              fout << "----------" << setiosflags(ios::showpoint) << setprecision(7) << endl; // used for organization and spacing of each calculation. (fout is for the output.txt file)
              fout << "Lower and Upper Bounds: " << lower << " " << upper << setiosflags(ios::showpoint) << setprecision(7) << endl;
              fout << "Increment: " << increment  << endl;
 
              fout << setiosflags(ios::showpoint) << setprecision(7); //shows decimal places in the output. setprecision is how many numbers it shows after the decimal (.0000000)
 
             
              fout << setw(7) << "x" << setw(20) << "sin(x)" << setw(20) << "my_sin(x)" << setw(20) << "e (x)" << setw(20)
                     << "my_el (x)" << setw(20) << "my_e (x)" <<  endl;
 
 
              for (double x = lower; x <= upper; x += increment){
 
                     fout << setw(20) << x << setw(100) << sin(x) << setw(100) << y << setw(100) << exp(x) << endl;
 
              }
             
              fout << endl;
              cout << "Another (y/n)? ";
              cin >> answer;
 
       } while (answer == 'y' || answer == 'Y');
      
       fout << endl;
 
       return 0;
}
//double fractorial(int x)
//{
//     double y = 1.0;
//     for (int n = 2; n <= x; ++n)
//            y *= (double)n;
//     return y;
//}
 
 
double factorial(int x)
{
       double y = 1.0;
       for (int n = 1; n <= x; ++n){
              y *= (double)n;
       }
       return y;
}
 
//n != n*(n - 1)*(n - 2) * 1;
 
//n = 1 n = 0 n >= 1
 
 
double myexp(double x)
{
       double accumSum = 0.0;
       double my_pow;
       double my_factorial = 0.0;
 
       for (int k = 0; k < 50; ++k) {
              accumSum = accumSum + my_pow(x, k) / my_factorial;
       }
       return accumSum;
}
 
This is how the program should look, my output is missing the last columns and also my calculations are incorrect.

User Inputs of 0 and 1
Incements of .1

http://i60.tinypic.com/w98c4k.png
Last edited on
Anyone?
Topic archived. No new replies allowed.