Thread: I can't find my error?

  1. #1
    Registered User
    Join Date
    Feb 2014
    Posts
    6

    Unhappy I can't find my error?

    To be clear i'm a newb, and I don't know what I did to prevent my code from running, any thoughts?

    insert
    Code:
    
    
    Code:
    #include<stdio.h>
    #include<math.h>
    #define PI 3.14159
    
    
    int main ()
    
    
    {
    int n;
    printf("Please enter a value: \n");
    scanf("%d",&n); 
    printf("\n");
    
    
    n! = ((pow(n,n)*exp(-n)*sqrt((2.0*n+(1.0/3.0))PI);
    
    
    printf("%d! equals approximately",n!);
    
    
    return 0;
    }
    
    

  2. #2
    Registered User
    Join Date
    May 2009
    Posts
    4,183
    I would start by removing the "!" sign in "n! =".

    Tim S.
    "...a computer is a stupid machine with the ability to do incredibly smart things, while computer programmers are smart people with the ability to do incredibly stupid things. They are,in short, a perfect match.." Bill Bryson

  3. #3
    Registered User
    Join Date
    Feb 2014
    Posts
    6
    I'm still stuck, here's the new code:


    #include<stdio.h>
    #include<math.h>
    #define PI 3.14159


    int main ()
    {
    int n;
    float x;
    printf("Please enter a value: \n");
    scanf("%d",&n);
    x = pow(n,n)*exp(-n)*sqrt(2*n+(1/3))*PI);
    printf("%d equals approximately",x);


    return 0;
    }
    Last edited by rocksolid; 02-08-2014 at 12:49 PM.

  4. #4
    C++ Witch laserlight's Avatar
    Join Date
    Oct 2003
    Location
    Singapore
    Posts
    28,413
    For starters, you should indent your code properly, e.g.,
    Code:
    #include<stdio.h>
    #include<math.h>
    
    #define PI 3.14159
    
    int main()
    {
        int n;
        float x;
        printf("Please enter a value: \n");
        scanf("%d", &n);
        x = pow(n, n) * exp(-n) * sqrt(2 * n + (1/3)) * PI);
        printf("%d equals approximately",x);
    
        return 0;
    }
    Next, I believe you have a compile error. What is the error message, and what do you understand of it?

    By the way, please post code in [code][/code] bbcode tags.
    Quote Originally Posted by Bjarne Stroustrup (2000-10-14)
    I get maybe two dozen requests for help with some sort of programming or design problem every day. Most have more sense than to send me hundreds of lines of code. If they do, I ask them to find the smallest example that exhibits the problem and send me that. Mostly, they then find the error themselves. "Finding the smallest program that demonstrates the error" is a powerful debugging tool.
    Look up a C++ Reference and learn How To Ask Questions The Smart Way

  5. #5
    Registered User
    Join Date
    Feb 2014
    Posts
    6
    This is what appears, I can't find my error?-lab-3-pic-jpg

  6. #6
    C++ Witch laserlight's Avatar
    Join Date
    Oct 2003
    Location
    Singapore
    Posts
    28,413
    So, take a look at this line and match each opening parenthesis with a closing parenthesis:
    Code:
    x = pow(n, n) * exp(-n) * sqrt(2 * n + (1/3)) * PI);
    Quote Originally Posted by Bjarne Stroustrup (2000-10-14)
    I get maybe two dozen requests for help with some sort of programming or design problem every day. Most have more sense than to send me hundreds of lines of code. If they do, I ask them to find the smallest example that exhibits the problem and send me that. Mostly, they then find the error themselves. "Finding the smallest program that demonstrates the error" is a powerful debugging tool.
    Look up a C++ Reference and learn How To Ask Questions The Smart Way

  7. #7
    Registered User
    Join Date
    Feb 2014
    Posts
    6
    I guess that last parenthesis was useless. LOL.

  8. #8
    C++ Witch laserlight's Avatar
    Join Date
    Oct 2003
    Location
    Singapore
    Posts
    28,413
    Yes. However, just because you have fixed all your compile errors does not mean that there is no logical error with your code, so carefully check to see if for various test input, the actual output is equal to the expected output.
    Quote Originally Posted by Bjarne Stroustrup (2000-10-14)
    I get maybe two dozen requests for help with some sort of programming or design problem every day. Most have more sense than to send me hundreds of lines of code. If they do, I ask them to find the smallest example that exhibits the problem and send me that. Mostly, they then find the error themselves. "Finding the smallest program that demonstrates the error" is a powerful debugging tool.
    Look up a C++ Reference and learn How To Ask Questions The Smart Way

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Can you find the error?
    By neeha_khan in forum C++ Programming
    Replies: 20
    Last Post: 04-15-2013, 07:02 AM
  2. Can't find any error
    By Khokhar in forum C Programming
    Replies: 2
    Last Post: 03-09-2013, 09:44 AM
  3. Can't find error
    By shadowsora15 in forum C++ Programming
    Replies: 5
    Last Post: 05-26-2007, 04:00 AM
  4. Cannot find error
    By rwmarsh in forum Game Programming
    Replies: 6
    Last Post: 09-20-2006, 06:48 AM
  5. can't find the error
    By noor_mirza in forum C++ Programming
    Replies: 2
    Last Post: 11-03-2002, 12:58 AM

Tags for this Thread