473,394 Members | 1,724 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,394 software developers and data experts.

radius of a star help writing program, need corrections?

15
hey im suppose to write a program using pelles C for windows to calculate the radius of the star using the formulas:

r = 1/2T^2 *sqrt( L/pi*σ)

L= 3.36192 *10^(140 - 2M/5)

σ = 5.67051*10^ -8

you are given and suppose to input the values for T and M to solve for r, so far I have this but im stuck and I dont even know if this is right:

Expand|Select|Wrap|Line Numbers
  1. #include <stdio.h>
  2. #include <math.h>
  3.  
  4. int main (void)
  5. {
  6.     double r, T, M;
  7.     // Read input data
  8.     printf("\nr = ");
  9.     scanf("%1f", &r);
  10.     printf("T= ");
  11.     scanf("&1f", &T);
  12.     printf("M=");
  13.     scanf("%1f", &M);
  14.  
  15.     //Perform calculation
  16.     r = ((1/2T^2)*(sqrt(3.36192*10^(140-2M/5)/(pi*5.67051*10^-8));
  17.             T=.................;
  18.             M=................;
  19.  
  20.             //Display output
  21.             printf("..............");
  22.             return 0;
  23.         }
  24.  
any help would be greatly appreciated, thanks.
Feb 13 '07 #1
28 2542
sicarie
4,677 Expert Mod 4TB
Comments in code:
Expand|Select|Wrap|Line Numbers
  1. #include <stdio.h>
  2. #include <math.h>
  3. // i would recommend declaring pi here as a global (as pi's value is not going to change), you don't declare it anywhere, you just use it
  4.  
  5. int main (void)
  6. {
  7.     double r, T, M; 
  8.     // Read input data
  9.     printf("\nr = ");
  10.     scanf("%1f", &r);
  11.     printf("T= ");
  12.     scanf("&1f", &T);
  13.     printf("M=");
  14.     scanf("%1f", &M);
  15.  
  16.     //Perform calculation
  17.     r = ((1/2T^2)*(sqrt(3.36192*10^(140-2M/5)/(pi*5.67051*10^-8));
  18.     // at 2T you need to change this to (1/2)*T and figure out if you want all of that squared, or just T
  19.     // and it is the same thing with 'M'
  20.    // and, of course, declare pi
  21.    // and you're missing one more pair of parentheses at the end
  22. //            T=.................;
  23. //            M=................;
  24.  
  25.             //Display output
  26.             printf("..............");
  27.             return 0;
  28.         }
  29.  
Try making those changes and see if it compiles, then re-post your code, and we can work on the rest!
Feb 13 '07 #2
Daleio
15
Comments in code:
Expand|Select|Wrap|Line Numbers
  1. #include <stdio.h>
  2. #include <math.h>
  3. // i would recommend declaring pi here as a global (as pi's value is not going to change), you don't declare it anywhere, you just use it
  4.  
  5. int main (void)
  6. {
  7.     double r, T, M; 
  8.     // Read input data
  9.     printf("\nr = ");
  10.     scanf("%1f", &r);
  11.     printf("T= ");
  12.     scanf("&1f", &T);
  13.     printf("M=");
  14.     scanf("%1f", &M);
  15.  
  16.     //Perform calculation
  17.     r = ((1/2T^2)*(sqrt(3.36192*10^(140-2M/5)/(pi*5.67051*10^-8));
  18.     // at 2T you need to change this to (1/2)*T and figure out if you want all of that squared, or just T
  19.     // and it is the same thing with 'M'
  20.    // and, of course, declare pi
  21.    // and you're missing one more pair of parentheses at the end
  22. //            T=.................;
  23. //            M=................;
  24.  
  25.             //Display output
  26.             printf("..............");
  27.             return 0;
  28.         }
  29.  
Try making those changes and see if it compiles, then re-post your code, and we can work on the rest!




I was kind of wondering how to put unknown variables into the program. I am given values for T and M and somehow im suppose to put them into the program to solve for r. Im not quite sure how to put the equations in the program. I am suppose to put in the values of T and M to solve for r. This is my main problem. Please Help.
Feb 14 '07 #3
sicarie
4,677 Expert Mod 4TB
I was kind of wondering how to put unknown variables into the program. I am given values for T and M and somehow im suppose to put them into the program to solve for r. Im not quite sure how to put the equations in the program. I am suppose to put in the values of T and M to solve for r. This is my main problem. Please Help.
If I understand you correctly, you either have a user inputting the variables, or you have a file with those variables, correct? (and which one?)

This is a page that details many different options you can use to get input from both the user and from a file (though you might have to do a little more digging if it is in a file - you can google "c read input from file" and you should get something, or you can post back here if you can't find anything).

Do those look like what you're trying to do, or did I miss what you were saying?
Feb 14 '07 #4
Daleio
15
these are the errors i get after i think i made all the corrections....

#include <stdio.h>
#include <math.h>

int main (void)
{
double r, T, M,pi;
// Read input data
printf("\nr = ");
scanf("%1f", &r);
printf("T= ");
scanf("&1f", &T);
printf("M=");
scanf("%1f", &M);

//Perform calculation
r = ((1/2*T^2)*(sqrt(3.36192*10^(140-2*M/5)/(pi*5.67051*10^-8)));
T=.................;
M=................;

//Display output
printf("..............");
return 0;
}




C:\Documents and Settings\......\Assign 2\radius.c(16): error #2168: Operands of ^ have incompatible types 'double' and 'int'.
C:\Documents and Settings\.....\Assign 2\radius.c(16): error #2168: Operands of ^ have incompatible types 'double' and 'int'.
C:\Documents and Settings\......\Assign 2\radius.c(16): error #2168: Operands of ^ have incompatible types 'double' and 'double'.
C:\Documents and Settings\......\Assign 2\radius.c(16): error #2001: Syntax error: found ';' - expecting ')'.
C:\Documents and Settings\........\Assign 2\radius.c(17): error #2039: Illegal expression.
C:\Documents and Settings\......\Assign 2\radius.c(17): error #2001: Syntax error: found '...' - expecting ';'.
C:\Documents and Settings\.......\Assign 2\radius.c(17): error #2061: Illegal statement termination.
C:\Documents and Settings\......\Assign 2\radius.c(18): error #2039: Illegal expression.
C:\Documents and Settings\........\Assign 2\radius.c(18): error #2001: Syntax error: found '...' - expecting ';'.
C:\Documents and Settings\.........\Assign 2\radius.c(18): error #2061: Illegal statement termination.
*** Error code: 1 ***

need help with these errors please. sorry im a newbie to programming
Feb 14 '07 #5
hirak1984
316 100+
make the return type of main to void.

Expand|Select|Wrap|Line Numbers
  1.  void main();
and not
Expand|Select|Wrap|Line Numbers
  1. int main(void)
may be this will help
these are the errors i get after i think i made all the corrections....

#include <stdio.h>
#include <math.h>

int main (void)
{
double r, T, M,pi;
// Read input data
printf("\nr = ");
scanf("%1f", &r);
printf("T= ");
scanf("&1f", &T);
printf("M=");
scanf("%1f", &M);

//Perform calculation
r = ((1/2*T^2)*(sqrt(3.36192*10^(140-2*M/5)/(pi*5.67051*10^-8)));
T=.................;
M=................;

//Display output
printf("..............");
return 0;
}




C:\Documents and Settings\......\Assign 2\radius.c(16): error #2168: Operands of ^ have incompatible types 'double' and 'int'.
C:\Documents and Settings\.....\Assign 2\radius.c(16): error #2168: Operands of ^ have incompatible types 'double' and 'int'.
C:\Documents and Settings\......\Assign 2\radius.c(16): error #2168: Operands of ^ have incompatible types 'double' and 'double'.
C:\Documents and Settings\......\Assign 2\radius.c(16): error #2001: Syntax error: found ';' - expecting ')'.
C:\Documents and Settings\........\Assign 2\radius.c(17): error #2039: Illegal expression.
C:\Documents and Settings\......\Assign 2\radius.c(17): error #2001: Syntax error: found '...' - expecting ';'.
C:\Documents and Settings\.......\Assign 2\radius.c(17): error #2061: Illegal statement termination.
C:\Documents and Settings\......\Assign 2\radius.c(18): error #2039: Illegal expression.
C:\Documents and Settings\........\Assign 2\radius.c(18): error #2001: Syntax error: found '...' - expecting ';'.
C:\Documents and Settings\.........\Assign 2\radius.c(18): error #2061: Illegal statement termination.
*** Error code: 1 ***

need help with these errors please. sorry im a newbie to programming
Feb 14 '07 #6
sicarie
4,677 Expert Mod 4TB
If you are going to do that, you need to remove the 'return 0;' at the bottom, otherwise you will get an error with main().
Feb 14 '07 #7
sicarie
4,677 Expert Mod 4TB
If you look at the error messages, everything your compiler is complaining about is on lines 16, 17, and 18.

You can delete 17 and 18, as far as I can tell, you don't need them.

Then on 16, you need to be careful on what you are multiplying to what and how:

r = (( 1/2 * T^2) * (sqrt(3.36192 * 10^(140 - 2 * M/5) / (pi * 5.67051 * 10^-8)));
I think you should break that part up into several different sections - it will be easier for you and the compiler.
Feb 14 '07 #8
Daleio
15
yeah tahnks i got most of the problem worked out the only error i get now after th enew code....

#include <stdio.h>
#include <math.h>

int main (void)
{
double r, T, M,pi, z,a,b;
// Read input data
printf("\nr = ");
scanf("%1f", &r);
printf("T= ");
scanf("&1f", &T);
printf("M=");
scanf("%1f", &M);

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


//Display output
printf("..............");
return 0;
}


C:\Documents and Settings\.....\Assign 2\radius.c(18): error #2001: Syntax error: found ';' - expecting ')'.
Feb 14 '07 #9
sicarie
4,677 Expert Mod 4TB
Actually, it looks pretty correct except that you need a ')' at the end of the statement, and you should change T^2 to pow(T,2) - that will return a double (while using the carat returns an int - which was what your compiler was saying).

(I'd still break it up, but that's just me - it looks very crammed to have all that in there on one line - I'm betting there will be a logic error in there somewhere...)
Feb 14 '07 #10
Daleio
15
nevermind i fix taht but get new error...

Expand|Select|Wrap|Line Numbers
  1. #include <stdio.h>
  2. #include <math.h>
  3.  
  4. int main (void)
  5. {
  6.     double r, T, M,pi, z,a,b;
  7.     // Read input data
  8.     printf("\nr = ");
  9.     scanf("%1f", &r);
  10.     printf("T= ");
  11.     scanf("&1f", &T);
  12.     printf("M=");
  13.     scanf("%1f", &M);
  14.  
  15.     //Perform calculation
  16.     r = ((1/2*z)*(sqrt(3.36192*a)/(pi*5.67051*b)));
  17.         z= pow(T,2);
  18.         a= pow(10,(140-2*M/5));
  19.         b=pow(10,-8);
  20.  
  21.  
  22.     //Display output
  23.             printf("..............");
  24.             return 0;
  25.         }
  26.  
C:\Documents and Settings\........\Assign 2\radius.c(6): warning #2115: Local 'z' is initialized but never used.
C:\Documents and Settings\........\Assign 2\radius.c(6): warning #2116: Local 'pi' is used but never assigned a value.
Feb 14 '07 #11
sicarie
4,677 Expert Mod 4TB
nevermind i fix taht but get new error...

Expand|Select|Wrap|Line Numbers
  1. #include <stdio.h>
  2. #include <math.h>
  3.  
  4. int main (void)
  5. {
  6.     double r, T, M,pi, z,a,b;
  7.     // Read input data
  8.     printf("\nr = ");
  9.     scanf("%1f", &r);
  10.     printf("T= ");
  11.     scanf("&1f", &T);
  12.     printf("M=");
  13.     scanf("%1f", &M);
  14.  
  15.     //Perform calculation
  16.     r = ((1/2*z)*(sqrt(3.36192*a)/(pi*5.67051*b)));
  17.         z= pow(T,2);
  18.         a= pow(10,(140-2*M/5));
  19.         b=pow(10,-8);
  20.  
  21.  
  22.     //Display output
  23.             printf("..............");
  24.             return 0;
  25.         }
  26.  
C:\Documents and Settings\........\Assign 2\radius.c(6): warning #2115: Local 'z' is initialized but never used.
C:\Documents and Settings\........\Assign 2\radius.c(6): warning #2116: Local 'pi' is used but never assigned a value.
So the first is telling you that you declared z, assigned a value to it, but then didn't use it again. I'm betting that you wanted T-squared in your answer somewhere there ;).

The second is saying that you declared pi, but you never assigned it the value of pi. My suggestion was for a global, so that would be like this:

Expand|Select|Wrap|Line Numbers
  1. #include //...
  2. #define PI    3.1415926
  3. int main() 
  4. // ...
  5.  
Then whenever you use PI, it will have the value of 3.1415926.
Feb 14 '07 #12
sicarie
4,677 Expert Mod 4TB
A side note that would otherwise lead to a logic error:

You declare the variables, but then go on to define them after you use them in a function. In C (and C++), when you define variables and do not give them values, they are initalized with whatever leftover values were in the memory allocated to them before they got there. This also known as 'junk' (was going to use a less-nice word there, but decided not to. You get the picture). Junk variables are hard to catch because they actually have a value, just not the one you think they do!

So I made some slight modifications below.

Expand|Select|Wrap|Line Numbers
  1. #include <stdio.h>
  2. #include <math.h>
  3. #define PI = 3.141592653
  4.  
  5. int main ( )
  6. {
  7.     double r, T, M, z,a,b;
  8.     // Read input data
  9.     printf("\nr = ");
  10.     scanf("%1f", &r);
  11.     printf("T= ");
  12.     scanf("&1f", &T);
  13.     printf("M=");
  14.     scanf("%1f", &M);
  15.  
  16.     //this change in order should help properly perform the calculation
  17.         z= pow(T,2);
  18.     a= pow(10,(140-2*M/5));
  19.     b=pow(10,-8);
  20.     r = ((1/2*z)*(sqrt(3.36192*a)/(pi*5.67051*b)));
  21.  
  22.     //Display output
  23.     printf("%d",r);
  24.     return 0;
  25. }
  26.  
Feb 14 '07 #13
Daleio
15
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
Feb 14 '07 #14
Daleio
15
#include <stdio.h>
#include <math.h>
#define pi 3.1415926

int main (void)
{
double r, T, M, z,a,b;
// Read input data
printf("\nr = ");
scanf("%1f", &r);
printf("T= ");
scanf("&1f", &T);
printf("M=");
scanf("%1f", &M);

//Perform calculation

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




//Display output
printf("The Radius is:");
return 0;
}
Feb 14 '07 #15
sicarie
4,677 Expert Mod 4TB
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!)
Feb 14 '07 #16
Daleio
15
thats ok thanks anyway you helped me out a lot
Feb 14 '07 #17
sicarie
4,677 Expert Mod 4TB
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.
Feb 14 '07 #18
Daleio
15
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
Feb 14 '07 #19
sicarie
4,677 Expert Mod 4TB
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!
Feb 14 '07 #20
sicarie
4,677 Expert Mod 4TB
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!
Feb 14 '07 #21
Daleio
15
changed it but still get the same error
Feb 14 '07 #22
Daleio
15
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;
}
Feb 14 '07 #23
sicarie
4,677 Expert Mod 4TB
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.

Expand|Select|Wrap|Line Numbers
  1. Printf("the radius is: %lf", r);
  2.  
Feb 14 '07 #24
Daleio
15
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.
Feb 15 '07 #25
sicarie
4,677 Expert Mod 4TB
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...
Feb 15 '07 #26
Daleio
15
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*pow(10,-8));
c=(140-2*M)/5;



//Display output
printf("\nThe Radius is: %lf\n",&r);
return 0;
}
Feb 15 '07 #27
Daleio
15
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
Feb 15 '07 #28
sicarie
4,677 Expert Mod 4TB
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!)
Feb 15 '07 #29

Sign in to post your reply or Sign up for a free account.

Similar topics

4
by: Xenophobe | last post by:
I have successfully created a zip code radius search, but the performance is unacceptable. I have two tables. The first is 52K zip codes w/lat and long. The second is 3K national business...
4
by: Aaron Collins | last post by:
Hello, How do I check the radius for a user if they come to my web site and I want to find out how far certain churches are from where they live. For instance, display results for churches that...
5
by: momo | last post by:
Can anyone help me? I am writing an ASP.NET app. and I need to be able to have people search based on X radius of a zip code. Please help. Thanks, Momo
0
by: JJ | last post by:
When the Chinese Star program is on, the textbox cannot get the chinese word, the data report cannot being open & the is error for the data report (Error Msg: Run-time error '8574' - the object...
9
by: Sandy | last post by:
Hello - I need either a cheap tool or code & DB that calculates, eg. within 50-mile radius of a zip code. Anyone have any suggestions? -- Sandy
9
by: ahmeddin | last post by:
How to calculate diameter, circumference and area of a circle by using radius--- Hello! I have been trying to learn C language.I bought a book "C How to Program,Deitel&Deitel"...I make practise...
3
by: arne.k.h | last post by:
Hi! :) Im new to python, and I have made a electronic diary - its just a task. Here is the code: http://pastebin.com/m49391798 The bug is (feel free to download and test it) that i can't see...
5
by: gubbachchi | last post by:
Hi, I need to store the star rated values in mysql. How will I do it. This is the code I have used to create the star rater, <ul class="star-rating small-star"> <li class="current-rating"...
0
by: Tony | last post by:
I am printing tickets with star tsp700 (743c) on the LPT1 with VB.NET program (I olso use C#). I use OCX control of STAR company. If I turn off printer or unplug cable, program for printing is...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.