GIDForums  

Go Back   GIDForums > Computer Programming Forums > C Programming Language
User Name
Password
Register FAQ Members List Calendar Search Today's Posts Mark Forums Read

 
 
Thread Tools Search this Thread Rate Thread
  #1  
Old 29-Sep-2005, 03:05
yumaslim yumaslim is offline
New Member
 
Join Date: Sep 2005
Posts: 2
yumaslim is on a distinguished road
Question

I have no Idea how to program


I'm new to programming in C, in fact I'm new to programming altogether. I have to write a program in C that:
computes the duration of a projectile's flight and it's height above the ground when it reaches the target.
Problem constant
G 32.17 (gravitational constant)
Problem Inputs
double theta (input angle)
double distance (distance to target)
double velocity (projectile velocity)
Problem outputs
double time (time of flight)
double height (height at impact)
relevant formulas
time=distance/ velocity x cos(theta)
height= velocity x sin(theta) x time - (g x time^2)/2

That is all of the info given in the book. I have no idea what to do with this info. I could really use some help with this. I know what all of the inputs and equations mean and I know how to do this on my own with paper, but I don't know how I would program this. I'd really appreciate any help on this subject.
  #2  
Old 29-Sep-2005, 03:14
cybemulatorC++ cybemulatorC++ is offline
New Member
 
Join Date: Sep 2005
Location: Born in Usa but living in Nepal coolest place in whole world...
Posts: 24
cybemulatorC++ is on a distinguished road

Re: I have no Idea how to program


Without knowing programming you won't be able to write that program. go to
http://www.cprogramming.com/ to learn C/C++
  #3  
Old 29-Sep-2005, 04:02
yumaslim yumaslim is offline
New Member
 
Join Date: Sep 2005
Posts: 2
yumaslim is on a distinguished road

Re: I have no Idea how to program


This is what I have so far, it is pretty bad. It won't even compile. If anyone could help out with the errors, or even if I am on the right track, I would appreciate it.

CPP / C++ / C Code:
/* projectile flight */
#include <stdio.h>
#include <math.h>
#define G 32.17 /*gravitational constant */

Double main()
{
0= double theta /* input – angle (radians) of elevation */
d= double distance /* input – distance to target*/
v= double velocity /* input – projectile velocity*/
printf( “Enter an angle for theta>”);
scanf(“%lf”, &theta);
printf(“Enter a distance>”);
scanf(“%lf”, &distance);
printf(“Enter a velocity>”);
double time= distance/ velocity*cos(theta)
double height=velocity*sin(theta)*time-G*time^2/2
printf(“time>”);
printf(“height>”);
{
return distance/velocity*cos(theta);
return velocity*sin(theta)*time-G*time^2/2;
}

The compiler is gcc, I don't know what that means, but it comes up with a lot of errors. The first of which is a parse error. What does that mean and how do I fix it? Again any help would be greatly appreciated.
Last edited by LuciWiz : 29-Sep-2005 at 04:24. Reason: Please insert your C code between [c] & [/c] tags
  #4  
Old 29-Sep-2005, 05:02
cybemulatorC++ cybemulatorC++ is offline
New Member
 
Join Date: Sep 2005
Location: Born in Usa but living in Nepal coolest place in whole world...
Posts: 24
cybemulatorC++ is on a distinguished road

Re: I have no Idea how to program


Describe me more and I may write this for you in C++(not in C). Tell me what are you trying to do more(in english)
  #5  
Old 29-Sep-2005, 06:33
Paramesh's Avatar
Paramesh Paramesh is offline
Regular Member
 
Join Date: Sep 2005
Location: The Milky Way
Posts: 929
Paramesh is a jewel in the roughParamesh is a jewel in the roughParamesh is a jewel in the rough

Re: I have no Idea how to program


hi...

The basic structure of main function is:
CPP / C++ / C Code:
int main()
{
declaration statements;
executable statements;
return(0);
}

Note that all the declaration should come first before you use any functions such as printf or scanf. This is the structure of the C program.
so declare your variables at the start before entering in to the program..



The general form of a variable declaration and assignment is:

type variable_name;

where type is one of the C variable types (int, float, etc.) Name is any valid variable
name.


Example:
CPP / C++ / C Code:
int i;

so you should not declare like this:
Quote:
0= double theta

You must add semicolon ; every time when you end a statement.

When you begin a curly brace { you should end with }. in your program you used an extra curly brace which is unnecessary and causes errors.

gcc is the name of the gnu C++ compiler which comes with linux...

and also note the general syntax of printf and scanf statements:
CPP / C++ / C Code:
int printf(
   const char *format [,
   argument]... 
);

int scanf(
   const char *format [,
   argument]... 
);

where
format:
Format control.
argument:
Optional arguments.
Return Value
Returns the number of characters successfully printed or successfully converted and assigned respectively, or a negative value if an error occurs.

Some examples of scanf and printf are:
CPP / C++ / C Code:
int i;                                           //declare an integer i
printf( " Enter the value of i.. " );     
scanf( " %d ",&i);                          //%d represents integer..scan for i
printf("The value of i is..... %d ",i);  //print i

and you need return statements only when you use functions(which you may learn later in the course)... so your return statements at the end is unnecessary and you can remove it..

And again, dont forget to insert semicolon at the end of each statement..

i hope this should help you to fix your errors...
bye,
Paramesh
  #6  
Old 29-Sep-2005, 10:35
alcedo's Avatar
alcedo alcedo is offline
Member
 
Join Date: Jul 2005
Location: Singapore
Posts: 203
alcedo will become famous soon enough

Re: I have no Idea how to program


i would strongly advice you to at least start learning basic input and output function first, instead of jumping STRAIGHT into solving programming questions =) step by step towards excellence.

Also realise that most compilers would change the color of keywords when you are coding, so you wont mix up keywords with variables.
__________________
People should read the rules and regulation before posting!

The Best is yet to be...
  #7  
Old 29-Sep-2005, 11:15
Guidelines Plz Guidelines Plz is offline
Junior Member
 
Join Date: Sep 2005
Posts: 87
Guidelines Plz is on a distinguished road

Re: I have no Idea how to program


Quote:
Originally Posted by yumaslim
The compiler is gcc, I don't know what that means, but it comes up with a lot of errors. The first of which is a parse error. What does that mean and how do I fix it? Again any help would be greatly appreciated.
Please.....
__________________

Please read http://www.gidforums.com/t-5566.html. They were written to help you create a request that is readable and has enough information we can actually tell what you need help with.
  #8  
Old 29-Sep-2005, 11:48
WaltP's Avatar
WaltP WaltP is offline
Outstanding Member
 
Join Date: Feb 2004
Location: Midwest US
Posts: 3,373
WaltP is a name known to allWaltP is a name known to allWaltP is a name known to allWaltP is a name known to allWaltP is a name known to allWaltP is a name known to all

Re: I have no Idea how to program


Quote:
Originally Posted by cybemulatorC++
Describe me more and I may write this for you in C++(not in C). Tell me what are you trying to do more(in english)
Around here we don't "write this for you". The poster does not learn that way. If he want's it written for him, he can hire a programmer. We help him solve it by giving suggestions and maybe a code snippet or two after he's posted his attempt at a solution.
__________________

The 3 Laws of the Procrastination Society:
1) Never do today that which can be put off until tomorrow
2) Tomorrow never comes
  #9  
Old 30-Sep-2005, 01:42
cybemulatorC++ cybemulatorC++ is offline
New Member
 
Join Date: Sep 2005
Location: Born in Usa but living in Nepal coolest place in whole world...
Posts: 24
cybemulatorC++ is on a distinguished road

Re: I have no Idea how to program


Quote:
Originally Posted by WaltP
Around here we don't "write this for you". The poster does not learn that way. If he want's it written for him, he can hire a programmer. We help him solve it by giving suggestions and maybe a code snippet or two after he's posted his attempt at a solution.

Doen't matter. By writting this program I don't want to waste my t-t-time.
  #10  
Old 30-Sep-2005, 05:04
cybemulatorC++ cybemulatorC++ is offline
New Member
 
Join Date: Sep 2005
Location: Born in Usa but living in Nepal coolest place in whole world...
Posts: 24
cybemulatorC++ is on a distinguished road

Re: I have no Idea how to program


And yes by using float in mathematical code you will get more accurate reasult than using int. You can use double too.
 
 

Recent GIDBlogProblems with the Navy (Enlisted) by crystalattice

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
Airport Log program using 3D linked List : problem reading from file batrsau C Programming Language 11 29-Feb-2008 07:44
Type casts ? kai85 C++ Forum 12 23-Jun-2005 12:04
[TUTORIAL] Calling an external program in C (Linux) dsmith C Programming Language 4 22-Apr-2005 13:30
fltk-2.0 cvs Plumb FLTK Forum 20 13-Nov-2004 07:10
Need help with a C program (Long) McFury C Programming Language 3 29-Apr-2004 20:06

Network Sites: GIDNetwork · GIDWebHosts · GIDSearch · Learning Journal by J de Silva, The

All times are GMT -6. The time now is 07:49.


vBulletin, Copyright © 2000 - 2010, Jelsoft Enterprises Ltd.