Originally posted by Daleio
radius of a star help writing program, need corrections?
Collapse
X
-
Originally posted by Daleiothats ok thanks anyway you helped me out a lot
Definitely let me know if you figure out that 'z' statement - I'll look at it tomorrow when I get back to work.Comment
-
Originally posted by Daleioi 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
Anyway, it's bedtime for me - I will look at it tomorrow, let me know if you figure it out!Comment
-
Originally posted by sicarieBut 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
-
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
-
Originally posted by Daleiohey 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;
}
Code:Printf("the radius is: %lf", r);
Comment
-
Originally posted by DaleioOk 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.
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
-
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
-
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 MComment
-
Originally posted by DaleioI 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
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
Comment