Thread: While Loop Problem

  1. #16
    Registered User
    Join Date
    Apr 2003
    Posts
    52
    well fabs is like abs but for floating point numbers, it sort of helps, but I need to sort more things out with this loop and the conditional statement..

  2. #17
    Registered User
    Join Date
    Apr 2003
    Posts
    52
    Ok, I pretty much give up, I hope to hear from any of you that might be able to help, here is some more fun output..
    I edited the while loop again so it gives me even more results, what I have isn't very nice and I don't know, I'm going to make sure the instructor sees what is wrong but if any of you can help, it will be nice. here it is.
    Code:
    double sine(double x, double precise)
    {
    	double term = 1;
    	int k = 1;
    	double sum = 0;
    	do 
    	{
    		cout << "k: " << k << endl;
    		cout << "multiplier: " << power(-1, k+1) << endl;
    		cout << "power: " << power(x,2*k-1) << endl;
    		cout << "factorial: " << factorial(2*k-1) << endl;
    		cout << "fabs: " << fabs(term) << endl;
    		cout << "term: " << term << endl;
    		cout << "sum: " << sum << endl;
    		cout << "sin: " << sin(x) << endl << endl;
    		
    		term = (power(-1, k+1) * (power(x, 2*k-1)/factorial(2*k-1)));
    		sum = sum + term;
    		k= k+1;
    	}while ((fabs(term)<precise) || (k<10));
    	return sum;
    }
    Hi, welcome to the Sine Function
    Please enter a angle for the Sine Function
    4
    To what precision?
    .001
    Is the value in degrees or radians?
    If the value is in degrees, type 'degrees', otherwise you
    may type anything else.
    no
    k: 1
    multiplier: 1
    power: 4
    factorial: 1
    fabs: 1
    term: 1
    sum: 0
    sin: -0.756802

    k: 2
    multiplier: -1
    power: 64
    factorial: 6
    fabs: 4
    term: 4
    sum: 4
    sin: -0.756802

    k: 3
    multiplier: 1
    power: 1024
    factorial: 120
    fabs: 10.6667
    term: -10.6667
    sum: -6.66667
    sin: -0.756802

    k: 4
    multiplier: -1
    power: 16384
    factorial: 5040
    fabs: 8.53333
    term: 8.53333
    sum: 1.86667
    sin: -0.756802

    k: 5
    multiplier: 1
    power: 262144
    factorial: 362880
    fabs: 3.25079
    term: -3.25079
    sum: -1.38413
    sin: -0.756802

    k: 6
    multiplier: -1
    power: 4.1943e+006
    factorial: 39916800
    fabs: 0.722399
    term: 0.722399
    sum: -0.661728
    sin: -0.756802

    k: 7
    multiplier: 1
    power: 6.71089e+007
    factorial: 1932053504
    fabs: 0.105076
    term: -0.105076
    sum: -0.766805
    sin: -0.756802

    k: 8
    multiplier: -1
    power: 1.07374e+009
    factorial: 2004310016
    fabs: 0.0347345
    term: 0.0347345
    sum: -0.73207
    sin: -0.756802

    k: 9
    multiplier: 1
    power: 1.71799e+010
    factorial: -288522240
    fabs: 0.535716
    term: -0.535716
    sum: -1.26779
    sin: -0.756802

    Ok thanks all! night!

  3. #18
    Registered User
    Join Date
    Apr 2003
    Posts
    52
    I was told by a certain poster here that "Salem would come. Salem would fix your problem". Thank you man, I really appreciate it. I'm going to study this in depth tommorow to really understand what you changed, I'm very tired now, but you helped me out a TON! THANKS

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Addition problem in loop
    By murjax in forum C Programming
    Replies: 3
    Last Post: 07-01-2009, 06:29 PM
  2. validation problem in a loop (newbie question)
    By Aisthesis in forum C++ Programming
    Replies: 11
    Last Post: 05-10-2009, 10:47 PM
  3. For Loop Problem
    By xp5 in forum C Programming
    Replies: 10
    Last Post: 09-05-2007, 04:37 PM
  4. Loop problem
    By Tesnik in forum C++ Programming
    Replies: 29
    Last Post: 08-23-2007, 10:24 AM
  5. A question related to strcmp
    By meili100 in forum C++ Programming
    Replies: 6
    Last Post: 07-07-2007, 02:51 PM