Sythe.Org Forums     Register     FAQ     Members List     Calendar     Mark Forums Read    
 
Sythe.Org Forums  
   Runescape Gold

Sythe.org — A Virtual Goods Trading Hub

Make real cash! buying and selling in-game items.

We have a no-scam policy.

You can make thousands playing your favourite games here at Sythe.org.

Just sign up an account and follow the rules!


Take me to

Runescape Markets

Other Game Markets

Support Center

Register an Account

Close
Need Quick Help
Reply
 
LinkBack Thread Tools Display Modes
  #1  
Old 08-23-2009, 01:16 PM
Forum Addict
BANNED
 
Join Date: Jul 2009
Posts: 251
Send a message via MSN to mmki
Default Need Quick Help

This is for an equation for the time it takes a pendlum to swing

#include <iostream>
#include <cmath>
#define PI 3.14159
#define G 9.8 //Gravity

using namespace std;

int main()
{
double l;
double e;
cout << "Enter Lengh of Rod\n";
cin >> l;
cout << "The time it takes from one swing is ";
cout << 2*PI*((l/G)^(1/2));
cin >> e;
return 0;
}





i get error; invalid operands of types `double' and `int' to binary `operator^'

HELP!!
thanks
Reply With Quote
  #2  
Old 08-23-2009, 10:48 PM
Swan's Avatar
When They Cry...
Ex-Moderator
 
Join Date: Jan 2007
Location: Japan
Posts: 4,404
Default Re: Need Quick Help

^ is a bitwise operator. It doesn't mean powers in C++.

I'd fix it for you, but I need to go to school.

You want to be using the pow() function which I believe is part of the math.h.

http://www.cplusplus.com/reference/clibrary/cmath/pow/
__________________
Quote:
[14:54:13] <&Filefragg> x9 is made of 5 glow in the dark gorilla dildos vibrating in unison.
[14:54:19] <%TDD> hot
[14:54:22] <+Aoi> Win
[14:54:23] <x9> I TOLD YOU NOT TO TELL ANYONE, DAMNIT
Reply With Quote
  #3  
Old 08-24-2009, 08:04 PM
Member
 
Join Date: Dec 2008
Posts: 91
Default Re: Need Quick Help

Code:
/*
 * pendulum_time.c
 *
 * Calculates the time for a pendulum to complete one swing.
 *
 * 8/24/09 - super_
 */

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

#define PI	3.14159
#define G	9.8

main() {
    double rod_length;
    double swing_time;

    printf("Enter length of rod: ");
    scanf("%lf", &rod_length);

    swing_time = 2 * PI * sqrt(rod_length / G);

    printf("Time it takes for one swing: %f\n", swing_time);

    return 0;
}
Improved.
Reply With Quote
  #4  
Old 08-24-2009, 10:22 PM
Swan's Avatar
When They Cry...
Ex-Moderator
 
Join Date: Jan 2007
Location: Japan
Posts: 4,404
Default Re: Need Quick Help

Quote:
Originally Posted by super_ View Post
Code:
/*
 * pendulum_time.c
 *
 * Calculates the time for a pendulum to complete one swing.
 *
 * 8/24/09 - super_
 */

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

#define PI	3.14159
#define G	9.81

int main(int argc, char* argv[]) {
    double rod_length;
    double swing_time;

    printf("Enter length of rod: ");
    scanf("%lf", &rod_length);

    swing_time = 2 * PI * sqrt(rod_length / G);

    printf("Time it takes for one swing: %f\n", swing_time);

    return 0;
}
Improved.
Improved again.
While that may be legitimate C code for some compilers, others won't like the fact that you haven't specified a data type for the main method. As for the command line arguments, it's simply good practice to place them there.

Also, I always thought that gravity was 9.81 rather than 9.8, but I suppose that won't matter too much.
__________________
Quote:
[14:54:13] <&Filefragg> x9 is made of 5 glow in the dark gorilla dildos vibrating in unison.
[14:54:19] <%TDD> hot
[14:54:22] <+Aoi> Win
[14:54:23] <x9> I TOLD YOU NOT TO TELL ANYONE, DAMNIT
Reply With Quote
  #5  
Old 08-24-2009, 11:45 PM
Member
 
Join Date: Dec 2008
Posts: 91
Default Re: Need Quick Help

Quote:
Originally Posted by Swan View Post
Improved again.
While that may be legitimate C code for some compilers, others won't like the fact that you haven't specified a data type for the main method. As for the command line arguments, it's simply good practice to place them there.

Also, I always thought that gravity was 9.81 rather than 9.8, but I suppose that won't matter too much.
It's legit for all compilers; implicit data type is int (k&r). Command line arguments aren't to be placed there; main() means 'function main with unknown arguments', not 'no arguments'. I leave it as 'unknown arguments' so that the real entry point can still push argc, argv, and envp on the stack but I don't need to access them. The stack is cleaned after main() returns anyway
Reply With Quote
  #6  
Old 08-25-2009, 07:19 AM
Swan's Avatar
When They Cry...
Ex-Moderator
 
Join Date: Jan 2007
Location: Japan
Posts: 4,404
Default Re: Need Quick Help

Quote:
Originally Posted by super_ View Post
It's legit for all compilers; implicit data type is int (k&r). Command line arguments aren't to be placed there; main() means 'function main with unknown arguments', not 'no arguments'. I leave it as 'unknown arguments' so that the real entry point can still push argc, argv, and envp on the stack but I don't need to access them. The stack is cleaned after main() returns anyway
What I'm saying is that you aren't exactly complying to the standard most people use, which can confuse people.

Also, many compilers will throw errors if you don't explicitly state the return type.
__________________
Quote:
[14:54:13] <&Filefragg> x9 is made of 5 glow in the dark gorilla dildos vibrating in unison.
[14:54:19] <%TDD> hot
[14:54:22] <+Aoi> Win
[14:54:23] <x9> I TOLD YOU NOT TO TELL ANYONE, DAMNIT
Reply With Quote
  #7  
Old 08-25-2009, 05:02 PM
Forum Addict
 
Join Date: Jul 2008
Location: Sweden
Posts: 328
Send a message via MSN to hampe-92
Default Re: Need Quick Help

Quote:
Originally Posted by Swan View Post
Also, I always thought that gravity was 9.81 rather than 9.8, but I suppose that won't matter too much.
pretty much of topic but, what gravity is equal to differs depending on where on the earth you are (e.g. in Sweden we use g ≈ 9.82)...
__________________
My system: Mac Pro, 2 x 2.8 GHz Quad-Core Intel Xeon, 10GB 800MHz DDR2 RAM, ATI Radeon HD 4870 512mb

Some people see the glass as half empty. Some see it as half full. I see it as a glass that's twice as big as it needs to be.


Reply With Quote
  #8  
Old 09-06-2009, 08:18 AM
Forum Addict
BANNED
 
Join Date: Jul 2009
Posts: 251
Send a message via MSN to mmki
Default Re: Need Quick Help

Thanks Tons Guys =)
Reply With Quote
  #9  
Old 10-21-2009, 11:10 AM
Active Member
 
Join Date: Jun 2008
Posts: 117
Default

It's legit for all compilers; implicit data type is int (k&r). Command line arguments aren't to be placed there; main() means 'function main with unknown arguments', not 'no arguments'. I leave it as 'unknown arguments' so that the real entry point can still push argc, argv, and envp on the stack but I don't need to access them. The stack is cleaned after main() returns anyway
__________________
In the middle of difficulty lies opportunity - Albert Einstein
Online College and University Blog
Reply With Quote
  #10  
Old 10-22-2009, 12:57 AM
Member
 
Join Date: Dec 2008
Posts: 91
Default Re: Need Quick Help

Quote:
Originally Posted by clint999 View Post
It's legit for all compilers; implicit data type is int (k&r). Command line arguments aren't to be placed there; main() means 'function main with unknown arguments', not 'no arguments'. I leave it as 'unknown arguments' so that the real entry point can still push argc, argv, and envp on the stack but I don't need to access them. The stack is cleaned after main() returns anyway
what is your purpose?
Reply With Quote
Reply



Cheap RS Gold Store  Runescape Gold

Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

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
Trackbacks are Off
Pingbacks are Off
Refbacks are Off

All times are GMT +1. The time now is 04:12 AM.


Powered by vBulletin® Version 3.6.4
Copyright ©2000 - 2013, Jelsoft Enterprises Ltd.
Search Engine Optimization by vBSEO 3.6.1