do you see anything wrong with this program?

This is a discussion on do you see anything wrong with this program? within the C Programming forums, part of the General Programming Boards category; Code: #include <stdio.h> int main () { double a; double b; double s1; double s2; double hyp; printf ("please give ...

  1. #1
    Registered User
    Join Date
    Aug 2005
    Posts
    38

    do you see anything wrong with this program?

    Code:
    #include <stdio.h>
    int main ()
    {
    double a;
    double b;
    double s1;
    double s2;
    double hyp;
    printf ("please give the value of side a\n");
    scanf ("%lf", &a);
    printf ("please give the value of side b\n");
    scanf ("%lf", &b);
    1a = (b* b) - (a* a);
    2a = (2* a)* (b);
    hyp = (a* a) + (b* b);
    printf ("side 1 equals ");
    printf ("%lf\n", s1);
    printf ("side 2 equals ");
    printf ("%lf\n", s2);
    printf ("hypotenuse equals ");
    printf ("%lf\n", hyp);
    return 0;
    }
    the program is for my friend, and she gets the error
    invalid suffix "a" on integer constant

    what is the problem?

  2. #2
    C++ Developer XSquared's Avatar
    Join Date
    Jun 2002
    Location
    Ontario, Canada
    Posts
    2,718
    Code:
    1a = (b* b) - (a* a);
    2a = (2* a)* (b);
    You haven't declared these variables, and also, variable names can't begin with numbers.
    Naturally I didn't feel inspired enough to read all the links for you, since I already slaved away for long hours under a blistering sun pressing the search button after typing four whole words! - Quzah

    You. Fetch me my copy of the Wall Street Journal. You two, fight to the death - Stewie

  3. #3
    cwr
    cwr is offline
    Registered Luser cwr's Avatar
    Join Date
    Jul 2005
    Location
    Sydney, Australia
    Posts
    869
    Plus if you're trying to apply pythagorus' theorem, the logic would be hyp = sqrt(a*a + b*b);

  4. #4
    Registered User
    Join Date
    Aug 2005
    Posts
    38
    Quote Originally Posted by XSquared
    Code:
    1a = (b* b) - (a* a);
    2a = (2* a)* (b);
    You haven't declared these variables, and also, variable names can't begin with numbers.
    dang... cant believe i missed those.... thx!

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Maze Program - What am I doing wrong?
    By Gipionocheiyort in forum C++ Programming
    Replies: 20
    Last Post: 08-02-2007, 01:31 PM
  2. Replies: 5
    Last Post: 01-13-2007, 01:14 AM
  3. What is wrong with my code? My first program......
    By coreyt1111 in forum C++ Programming
    Replies: 11
    Last Post: 11-14-2006, 01:03 PM
  4. Whats wrong with this program - Output of a series
    By duffmckagan in forum C Programming
    Replies: 2
    Last Post: 07-26-2006, 09:57 AM
  5. Whats wrong with my program?
    By Ruflano in forum C++ Programming
    Replies: 5
    Last Post: 02-21-2002, 04:09 PM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21