radius of a star help writing program, need corrections?

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • sicarie
    Recognized Expert Specialist
    • Nov 2006
    • 4677

    #16
    Originally posted by Daleio
    i got the pi to work but i did use z in my r = equation right after the 1/2 i dont know why it says i dont use it the b and a work fine though
    That is weird. Is it still throwing the error? (I literally JUST re-installed this computer anyway, and don't yet have any other programs installed, so I don't ahve a C compiler in front of me - sorry!)

    Comment

    • Daleio
      New Member
      • Feb 2007
      • 15

      #17
      thats ok thanks anyway you helped me out a lot

      Comment

      • sicarie
        Recognized Expert Specialist
        • Nov 2006
        • 4677

        #18
        Originally posted by Daleio
        thats ok thanks anyway you helped me out a lot
        Anytime! And be careful about that r= statement - I believe that the * has precedence over / . (Which means 1/2*z might end up being (1 / (2 * z ))!)

        Definitely let me know if you figure out that 'z' statement - I'll look at it tomorrow when I get back to work.

        Comment

        • Daleio
          New Member
          • Feb 2007
          • 15

          #19
          i think the problem is that in the z= statement i use T but T is an unknown. Is there a way to a T= statement if T is a number i want to input into the program

          Comment

          • sicarie
            Recognized Expert Specialist
            • Nov 2006
            • 4677

            #20
            Originally posted by Daleio
            i think the problem is that in the z= statement i use T but T is an unknown. Is there a way to a T= statement if T is a number i want to input into the program
            But it looks like you input that with the scanf, and it should have given that warning about M as well...

            Anyway, it's bedtime for me - I will look at it tomorrow, let me know if you figure it out!

            Comment

            • sicarie
              Recognized Expert Specialist
              • Nov 2006
              • 4677

              #21
              Originally posted by sicarie
              But it looks like you input that with the scanf, and it should have given that warning about M as well...

              Anyway, it's bedtime for me - I will look at it tomorrow, let me know if you figure it out!
              I think that is it, actually. If you look at the scanf - you use an & ampersand when in the rest you use a % percent. Try changing that!

              Comment

              • Daleio
                New Member
                • Feb 2007
                • 15

                #22
                changed it but still get the same error

                Comment

                • Daleio
                  New Member
                  • Feb 2007
                  • 15

                  #23
                  hey I worked all the problems out but I dont get an answer, do you know what I did wrong, here is my updated code:


                  #include <stdio.h>
                  #include <math.h>
                  #define pi 3.1415926

                  int main (void)
                  {
                  double r, T, M;
                  // Read input data
                  printf("T= ");
                  scanf("%lf", &T);
                  printf("\nM=");
                  scanf("%lf", &M);

                  //Perform calculation


                  r = ((1/2)* pow(T,2))*(sqrt (3.36192*pow(10 ,(140-2*M/5)))/(pi*5.67051*pow (10,-8)));




                  //Display output
                  printf("The Radius is: ",r);
                  return 0;
                  }

                  Comment

                  • sicarie
                    Recognized Expert Specialist
                    • Nov 2006
                    • 4677

                    #24
                    Originally posted by Daleio
                    hey I worked all the problems out but I dont get an answer, do you know what I did wrong, here is my updated code:


                    #include <stdio.h>
                    #include <math.h>
                    #define pi 3.1415926

                    int main (void)
                    {
                    double r, T, M;
                    // Read input data
                    printf("T= ");
                    scanf("%lf", &T);
                    printf("\nM=");
                    scanf("%lf", &M);

                    //Perform calculation


                    r = ((1/2)* pow(T,2))*(sqrt (3.36192*pow(10 ,(140-2*M/5)))/(pi*5.67051*pow (10,-8)));




                    //Display output
                    printf("The Radius is: ",r);
                    return 0;
                    }
                    Printf() requires you to insert a representation of the variable in the output where you want it to show up. To represent a variable, you use the percent sign %, and 'lf' for a double.

                    Code:
                    Printf("the radius is: %lf", r);

                    Comment

                    • Daleio
                      New Member
                      • Feb 2007
                      • 15

                      #25
                      Ok I get a number now but whatever number i put in for T and M i only get the answer 0.0000. Is there some reason why th eprogram is not performing the calculation right.

                      Comment

                      • sicarie
                        Recognized Expert Specialist
                        • Nov 2006
                        • 4677

                        #26
                        Originally posted by Daleio
                        Ok I get a number now but whatever number i put in for T and M i only get the answer 0.0000. Is there some reason why th eprogram is not performing the calculation right.
                        (My C compiler is installing right now...) I think it's probably something in that r= statement. Can you go through and put parentheses around the individual actions?

                        For instance, part if it is (1/2*T^2) - should it be ((1/2)*(T^2))? or another way? There are all sorts of operator precedence rules in compilers, and that's why I was trying to get you to shorten this...

                        Comment

                        • Daleio
                          New Member
                          • Feb 2007
                          • 15

                          #27
                          hey i broke it up even more but still dont get right answer, heres the new code do you see anything wrong with it......


                          #include <stdio.h>
                          #include <math.h>
                          #define pi 3.1415926

                          int main (void)
                          {
                          double r, T, M, L,a,b,c;
                          // Read input data
                          printf("T= ");
                          scanf("%lf", &T);
                          printf("\nM=");
                          scanf("%lf", &M);

                          //Perform calculation


                          r = a*(sqrt(L/b));
                          L= 3.36192*pow(10, c);
                          a= 1/(2*pow(T,2));
                          b=pi*(5.67051*p ow(10,-8));
                          c=(140-2*M)/5;



                          //Display output
                          printf("\nThe Radius is: %lf\n",&r);
                          return 0;
                          }

                          Comment

                          • Daleio
                            New Member
                            • Feb 2007
                            • 15

                            #28
                            I think the problems is because the values i out in for M and T do not register and are not being used because no matter what numbers i put in for them the answer is always the same. Is there something i have to do to tell the program that the values i enter are for T and M

                            Comment

                            • sicarie
                              Recognized Expert Specialist
                              • Nov 2006
                              • 4677

                              #29
                              Originally posted by Daleio
                              I think the problems is because the values i out in for M and T do not register and are not being used because no matter what numbers i put in for them the answer is always the same. Is there something i have to do to tell the program that the values i enter are for T and M
                              That should already be in place with the scanf's.

                              In each one, you get a double with the %lf, and then you tell it to be in the value of T and M with the &. You can try it without the ampersands, see if that makes a difference, but I believe those are right.

                              (stupid ubuntu doesn't install gcc! I'm really annoyed at them, and stumped, I thought the full install came with it, but I dont' have it!)

                              Comment

                              Working...