| View previous topic :: View next topic   | 
	
	
	
		| Author | 
		Message | 
	
	
		Losplagos Expert Cheater
  Reputation: 0
  Joined: 21 Mar 2006 Posts: 172 Location: Knee deep in a c++ book
  | 
		
			
				 Posted: Tue May 15, 2007 2:36 am    Post subject: My first c++ program | 
				       | 
			 
			
				
  | 
			 
			
				I'm Pyro the Noob and this is my first c++ program i have made by myself no book giving me source code. I might of messed up the gravitational formula.
	
  
	 
	
	 
 _________________
   
 
Earthbound = 31337 | 
			 
		  | 
	
	
		| Back to top | 
		 | 
	
	
		  | 
	
	
		kennny2004 Advanced Cheater
  Reputation: 0
  Joined: 22 Jan 2006 Posts: 59 Location: Canada
  | 
		
			
				 Posted: Tue May 15, 2007 3:23 pm    Post subject:  | 
				       | 
			 
			
				
  | 
			 
			
				what it does, not up for getting more staff on my desktop lol mabie post the source
 _________________
 Hey was up! lol, simple heh  | 
			 
		  | 
	
	
		| Back to top | 
		 | 
	
	
		  | 
	
	
		Losplagos Expert Cheater
  Reputation: 0
  Joined: 21 Mar 2006 Posts: 172 Location: Knee deep in a c++ book
  | 
		
			
				 Posted: Tue May 15, 2007 7:37 pm    Post subject:  | 
				       | 
			 
			
				
  | 
			 
			
				 	  | Code: | 	 		  #include <cstdio>
 
#include <cstdlib>
 
#include <iostream>
 
using namespace std;
 
int main(int nNumberofArgs, char* pszArgs[])
 
{
 
// declaring variables
 
double M1;
 
double M2;
 
double Distance;
 
double G;
 
double Answer;
 
int Filler;
 
//The messages and storing variables
 
cout << "What is the First objects mass: ";
 
cin >> M1;
 
 
cout << "What is the second objects mass: ";
 
cin >> M2;
 
 
cout << "What is the distance between the centers of gravity of the two objects: ";
 
cin >> Distance;
 
 
//Here im doing the math
 
Answer =(G * M1 * M2)/(Distance * Distance);
 
G = 6.67300;
 
//And now i print the answer
 
cout << "The answer is: " << Answer <<  endl;
 
cout << "This program was made by " << "Pyro";
 
cin >> Filler;
 
return 0;
 
}
 
 | 	  
 
 
It is a simple program for gravitational force calculation I hope I set up the math correctly.
 _________________
   
 
Earthbound = 31337 | 
			 
		  | 
	
	
		| Back to top | 
		 | 
	
	
		  | 
	
	
		DeltaFlyer Grandmaster Cheater
  Reputation: 0
  Joined: 22 Jul 2006 Posts: 666
 
  | 
		
			
				 Posted: Tue May 15, 2007 8:33 pm    Post subject:  | 
				       | 
			 
			
				
  | 
			 
			
				You probably should set the constant G before you use it.
 _________________
  
 
Wow.... still working at 827... what's INCA thinking?
 
zomg l33t hax at  this place (IE only). Over 150 people have used it, what are YOU waiting for? | 
			 
		  | 
	
	
		| Back to top | 
		 | 
	
	
		  | 
	
	
		Losplagos Expert Cheater
  Reputation: 0
  Joined: 21 Mar 2006 Posts: 172 Location: Knee deep in a c++ book
  | 
		
			
				 Posted: Wed May 16, 2007 12:50 am    Post subject:  | 
				       | 
			 
			
				
  | 
			 
			
				Alright i fixed my code so it should actually work now.
 
 
Here is my source code.
 
 
 
 	  | Code: | 	 		  #include <cstdio>
 
#include <cstdlib>
 
#include <iostream>
 
using namespace std;
 
int main(int nNumberofArgs, char* pszArgs[])
 
{
 
// declaring variables
 
double dM1;
 
double dM2;
 
double dDistance;
 
double dAnswer;
 
double dFiller;
 
double dG;
 
double dA;
 
double dB;
 
// The constant for gravity
 
dG = 6.673;
 
//The messages and storing variables
 
cout << "What is the First objects mass: ";
 
cin >> dM1;
 
 
cout << "What is the second objects mass: ";
 
cin >> dM2;
 
 
cout << "What is the distance between the centers of gravity of the two objects: ";
 
cin >> dDistance;
 
 
//Here im doing the math
 
dA = dDistance * dDistance;
 
dB = dG * dM1 * dM2;
 
dAnswer = dB/dA;
 
//And now i print the answer
 
cout << "The answer is: " << dAnswer <<  endl;
 
cout << "This program was made by " << "Me";
 
cin >> dFiller;
 
return 0;
 
}
 
 | 	  
	
  
	 
	
	 
 _________________
   
 
Earthbound = 31337 | 
			 
		  | 
	
	
		| Back to top | 
		 | 
	
	
		  | 
	
	
		TheSorc3r3r I post too much
  Reputation: 0
  Joined: 06 Sep 2006 Posts: 2404
 
  | 
		
			
				 Posted: Wed May 16, 2007 4:40 am    Post subject:  | 
				       | 
			 
			
				
  | 
			 
			
				Here's a revised version (although I don't think that formula/constant is right.. what do I know!?  I just learned Inertia    )
 
 
 	  | Code: | 	 		  #include <iostream>
 
using namespace std;
 
 
#define GRAVITY 6.673
 
 
int main()
 
{
 
double mass1 = 0, mass2 = 0, distance = 0;
 
 
cout << "GravityCalculator\nby LosPlagos"
 
<< "\n\nEnter the first object's mass: ";
 
cin >> mass1;
 
cout << "\nEnter the second object's mass: ";
 
cin >> mass2;
 
cout << "\nEnter the distance between each objects' center of gravity: ";
 
cin >> distance;
 
 
if (!(mass1 & mass2 & distance))
 
{
 
cout << "\nError:  You didn't enter something correctly."
 
return 1;
 
}
 
 
cout << "\nAnswer is: " << (GRAVITY * mass1 * mass2)/(distance) << endl;
 
return 1;
 
} | 	  
 _________________
  
 
 
Don't laugh, I'm still learning photoshop!
  Last edited by TheSorc3r3r on Wed May 16, 2007 7:15 pm; edited 1 time in total | 
			 
		  | 
	
	
		| Back to top | 
		 | 
	
	
		  | 
	
	
		Losplagos Expert Cheater
  Reputation: 0
  Joined: 21 Mar 2006 Posts: 172 Location: Knee deep in a c++ book
  | 
		
			
				 Posted: Wed May 16, 2007 4:46 am    Post subject:  | 
				       | 
			 
			
				
  | 
			 
			
				The gravatational constant is probly wrong since i did it all from memory. 
 
Also i just started learning if commands.
 _________________
   
 
Earthbound = 31337 | 
			 
		  | 
	
	
		| Back to top | 
		 | 
	
	
		  | 
	
	
		D@ntheman How do I cheat?
  Reputation: 0
  Joined: 14 Dec 2006 Posts: 2
 
  | 
		
			
				 Posted: Wed May 16, 2007 9:00 am    Post subject:  | 
				       | 
			 
			
				
  | 
			 
			
				Thats a fine looking program you've made ther.
 _________________
 not a 1337 haxor!  | 
			 
		  | 
	
	
		| Back to top | 
		 | 
	
	
		  | 
	
	
		the_undead Expert Cheater
  Reputation: 1
  Joined: 12 Nov 2006 Posts: 235 Location: Johannesburg, South Africa
  | 
		
			
				 Posted: Wed May 16, 2007 9:07 am    Post subject:  | 
				       | 
			 
			
				
  | 
			 
			
				Dont make gravity a constant concidering some of us use 9.98m/s^2 as the value.
 _________________
  | 
			 
		  | 
	
	
		| Back to top | 
		 | 
	
	
		  | 
	
	
		Flyte Peanuts!!!!
  Reputation: 6
  Joined: 19 Apr 2006 Posts: 1887 Location: Canada
  | 
		
			
				 Posted: Wed May 16, 2007 10:10 am    Post subject:  | 
				       | 
			 
			
				
  | 
			 
			
				 	  | the_undead wrote: | 	 		  | Dont make gravity a constant concidering some of us use 9.98m/s^2 as the value. | 	  
 
 
The gravitaional constant (G) is 6.67e-11. 
 
9.81m/s^2 is the acceleration caused by Earth's gravity.
 
 
Also:
 
Your formula is incorrect. 
 
Fg = (G(m1)(m2))/(R^2) Is the correct one.
 | 
			 
		  | 
	
	
		| Back to top | 
		 | 
	
	
		  | 
	
	
		Losplagos Expert Cheater
  Reputation: 0
  Joined: 21 Mar 2006 Posts: 172 Location: Knee deep in a c++ book
  | 
		
			
				 Posted: Wed May 16, 2007 6:44 pm    Post subject:  | 
				       | 
			 
			
				
  | 
			 
			
				 	  | Flyte wrote: | 	 		   	  | the_undead wrote: | 	 		  | Dont make gravity a constant concidering some of us use 9.98m/s^2 as the value. | 	  
 
 
The gravitaional constant (G) is 6.67e-11. 
 
9.81m/s^2 is the acceleration caused by Earth's gravity.
 
 
Also:
 
Your formula is incorrect. 
 
Fg = (G(m1)(m2))/(R^2) Is the correct one. | 	  
 
 
Could you explain what r^2 is since the formula I remember is g*m1*m2/d^2 and is what I used. The current formula im using has these lines of code now.
 
 
 	  | Code: | 	 		  
 
dG = 6.67e-11;
 
dA = dDistance*dDistance;
 
dB = dG * dM1 * dM2;
 
 
 | 	  
 _________________
   
 
Earthbound = 31337 | 
			 
		  | 
	
	
		| Back to top | 
		 | 
	
	
		  | 
	
	
		Flyte Peanuts!!!!
  Reputation: 6
  Joined: 19 Apr 2006 Posts: 1887 Location: Canada
  | 
		
			
				 Posted: Thu May 17, 2007 2:55 pm    Post subject:  | 
				       | 
			 
			
				
  | 
			 
			
				 	  | Losplagos wrote: | 	 		   	  | Flyte wrote: | 	 		   	  | the_undead wrote: | 	 		  | Dont make gravity a constant concidering some of us use 9.98m/s^2 as the value. | 	  
 
 
The gravitaional constant (G) is 6.67e-11. 
 
9.81m/s^2 is the acceleration caused by Earth's gravity.
 
 
Also:
 
Your formula is incorrect. 
 
Fg = (G(m1)(m2))/(R^2) Is the correct one. | 	  
 
 
Could you explain what r^2 is since the formula I remember is g*m1*m2/d^2 and is what I used. The current formula im using has these lines of code now.
 
 
 	  | Code: | 	 		  
 
dG = 6.67e-11;
 
dA = dDistance*dDistance;
 
dB = dG * dM1 * dM2;
 
 
 | 	 
  | 	  
 
 
Sorry, I didn't notice that you did square the radius in the code by multiplying.
 
 
R and d are the same, just different variables. 
 
R (Radius)
 
d (distance)
 | 
			 
		  | 
	
	
		| Back to top | 
		 | 
	
	
		  | 
	
	
		krndandaman Cheater
  Reputation: 0
  Joined: 11 Nov 2006 Posts: 26
 
  | 
		
			
				 Posted: Thu May 17, 2007 5:12 pm    Post subject:  | 
				       | 
			 
			
				
  | 
			 
			
				How'd you learn this? 
 
Its a cool program.
 
From highschool class?
 
If its from a webtut, could you PM me a link?
 
If you could, that'd be great.
 
thanks in advance!
 _________________
 I'm mainly focused on GameCheetah sorry if I'm not here often.
 
A Wise man once said:"Beware of 'cute' people on MS cause anybody, including 50 year old men, can be 'cute' in MS."  | 
			 
		  | 
	
	
		| Back to top | 
		 | 
	
	
		  | 
	
	
		Losplagos Expert Cheater
  Reputation: 0
  Joined: 21 Mar 2006 Posts: 172 Location: Knee deep in a c++ book
  | 
		
			
				 Posted: Thu May 17, 2007 7:15 pm    Post subject:  | 
				       | 
			 
			
				
  | 
			 
			
				No class just what i have learned so far all I have used to make this you could learn in a day of c++ learning you could do the same.
 _________________
   
 
Earthbound = 31337 | 
			 
		  | 
	
	
		| Back to top | 
		 | 
	
	
		  | 
	
	
		 |