CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 9 of 9

Thread: calculate log

  1. #1
    Join Date
    Nov 2011
    Posts
    5

    calculate log

    how to do function to calc:

    a = log b / log c(1-d)

    if user need to input b, c and d?

    tq.

  2. #2
    Join Date
    Apr 1999
    Posts
    27,449

    Re: calculate log

    Quote Originally Posted by hawtchocolate View Post
    if user need to input b, c and d?
    Do you know how to call C++ functions? Then the function you want is in <cmath>.

    http://www.cplusplus.com/reference/clibrary/cmath/log/

    Regards,

    Paul McKenzie

  3. #3
    Join Date
    Nov 2011
    Posts
    5

    Re: calculate log

    a = (log10 (b)) / (log10 (C*(1-d)) );

    i try dis but i stil cant get the value of a. any help?
    tq

  4. #4
    VictorN's Avatar
    VictorN is offline Super Moderator Power Poster
    Join Date
    Jan 2003
    Location
    Hanover Germany
    Posts
    20,396

    Re: calculate log

    What do you mean by "cant get the value of a"?
    Victor Nijegorodov

  5. #5
    Join Date
    Nov 2011
    Posts
    5

    Re: calculate log

    it display nothing when i compiled;

    n = *nothing here.

    the equation is correct or not? =.='

  6. #6
    Join Date
    Nov 2011
    Posts
    5

    Re: calculate log

    #include <iostream>
    #include <math.h>

    int main ()
    {
    float S, n, C, d;

    cout << "Please enter S value :";
    cin >> S ;

    cout << "Please enter C value :";
    cin >> C;

    cout << "Please enter d value :";
    cin >> d;

    n = (log10 (S)) / (log10 (C*(1-d)) );

    printf ("n = ", n );
    return 0;
    }


    dis is what i tried. =.=

  7. #7
    VictorN's Avatar
    VictorN is offline Super Moderator Power Poster
    Join Date
    Jan 2003
    Location
    Hanover Germany
    Posts
    20,396

    Re: calculate log

    Quote Originally Posted by hawtchocolate View Post
    Code:
    #include <iostream>
    #include <math.h>
    
    int main ()
    {
      float S, n, C, d;
      ...
      n = (log10 (S)) / (log10 (C*(1-d)) );
     
      printf ("n = ", n );
      return 0;
    }
    You must specify the format (like %f) to print your variable. See examples (and description) in printf, wprintf article.
    Victor Nijegorodov

  8. #8
    Join Date
    Nov 2011
    Posts
    5

    Re: calculate log

    thanx for ur fast reply.im quite new in c++.

    whats the different if i use
    cout << "n = " << n ;

    ??
    n one more thing when i compiled, it said
    " 'cout' was not declared in this scope "

  9. #9
    Join Date
    Apr 1999
    Posts
    27,449

    Re: calculate log

    Quote Originally Posted by hawtchocolate View Post
    whats the different if i use
    cout << "n = " << n ;
    cout and operator << when given a double knows how to display it to the console. There is no format specifier necessary.
    n one more thing when i compiled, it said
    " 'cout' was not declared in this scope "
    Have you written a basic "Hello World" program in C++?
    Code:
    #include <iostream>
    using namespace std;
    
    int main()
    {
        cout << "Hello World";
    }
    This compiles and runs.

    Regards,

    Paul McKenzie

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured