Cheat Engine Forum Index Cheat Engine
The Official Site of Cheat Engine
 
 FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 


Here is my noob c++ calculation program that is a form test
Goto page Previous  1, 2, 3
 
Post new topic   Reply to topic    Cheat Engine Forum Index -> General programming
View previous topic :: View next topic  
Author Message
nog_lorp
Grandmaster Cheater
Reputation: 0

Joined: 26 Feb 2006
Posts: 743

PostPosted: Sun Aug 26, 2007 6:41 pm    Post subject: Reply with quote

camelCase is good.

Also, if you aren't gonna calculate pi, use
#define PI 3.14159
instead of making a new variable for it.

_________________
Mutilated lips give a kiss on the wrist of the worm-like tips of tentacles expanding in my mind
I'm fine accepting only fresh brine you can get another drop of this yeah you wish
Back to top
View user's profile Send private message
Losplagos
Expert Cheater
Reputation: 0

Joined: 21 Mar 2006
Posts: 172
Location: Knee deep in a c++ book

PostPosted: Sun Aug 26, 2007 7:13 pm    Post subject: Reply with quote

DeltaFlyer wrote:
That is not called optimizing, that's called being cheap with your screen space. Not indenting the code not only hurts others when trying to read your code, but also yourself when you try to debug it.

Also,
Code:
if (V==0&V>400)
As I understand, should be
Code:
if (V==0 || V>400)


One more thing: as by convention, variable names should be in lowerCamel case, beginning the first word with a lower case, then every other word with a capital letter. Constants such as PI should be in ALL CAPS. You can find more naming conventions online. These help people reading your code to more easily distinguish between elements.


I consider cutting the code needed in half almost optimizing. And i have just learned what i could pick up from multiple source not telling how to indent code.
I dont know about the (V==0 || V>400) since i never fully learned the || operator.
I will get better at all of this once my books come so i actually have solid written resources for noobs like me
And does this source look better.
Code:
#include <iostream>
#define PI 3.14159
int main()
{
std::cout << "Ok so enter a negetive number to exit the calculation program\n";
std::cout << "This program calculates how far a gunbound shot will travel\n";
std::cout << "There are your shot calculations\n Put in 0 to quit\n";
for(double  g,b,v,u,r;;){
std::cout << "What is The gravity of your shot?: ";
std::cin >> g;
if (g==0)
return EXIT_SUCCESS;
std::cout << "What is The angle of the shot?: ";
std::cin >> b;
if (b==0)
return EXIT_SUCCESS;
std::cout << "What is the power of the shot in pixels?: ";
std::cin >> v;
if (v==0&v>400)
return EXIT_SUCCESS;
u = (PI/180)*b;
r = (v*v)*sin(2*u) / g;
std::cout
<<"Answer = "
<< r<<std::endl;}}

_________________

Earthbound = 31337
Back to top
View user's profile Send private message
nog_lorp
Grandmaster Cheater
Reputation: 0

Joined: 26 Feb 2006
Posts: 743

PostPosted: Sun Aug 26, 2007 9:28 pm    Post subject: Reply with quote

Ok, here is the most basic principle:
When you write a {, indent the next line, when you write a }, you unindent right before. So,

Stuff {
indentation
. . .
} //unindentation

_________________
Mutilated lips give a kiss on the wrist of the worm-like tips of tentacles expanding in my mind
I'm fine accepting only fresh brine you can get another drop of this yeah you wish
Back to top
View user's profile Send private message
DeltaFlyer
Grandmaster Cheater
Reputation: 0

Joined: 22 Jul 2006
Posts: 666

PostPosted: Sun Aug 26, 2007 11:52 pm    Post subject: Reply with quote

Losplagos wrote:
I consider cutting the code needed in half almost optimizing.
Again, that is only true if you're optimizing for smallest screen space which is very pointless.

Losplagos wrote:
And i have just learned what i could pick up from multiple source not telling how to indent code.

Then read this article:
http://en.wikipedia.org/wiki/Indent_style

The first three is the most used for C based syntax.

Losplagos wrote:
I dont know about the (V==0 || V>400) since i never fully learned the || operator.


Never learned boolean OR, but already learned bitwise AND? || means in english: OR. Since you probably want to test if V is equal to 0 OR greater than 400, if true then exit. Your current code is saying to take the two boolean values, and do a bitwise AND between them, which doesn't make sense since the if statement will never be true.

Losplagos wrote:
I will get better at all of this once my books come so i actually have solid written resources for noobs like me

Programming is very computer oriented. I have therefore never found books to be helpful in programming. But I guess each person has his/her own likings.

Losplagos wrote:
And does this source look better.

No, it looks horrible and difficult to read. Indent your code! If you don't want to do it, search on Google for an auto-indenter.

_________________

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
View user's profile Send private message
hcavolsdsadgadsg
I'm a spammer
Reputation: 26

Joined: 11 Jun 2007
Posts: 5801

PostPosted: Mon Aug 27, 2007 12:26 am    Post subject: Reply with quote

VS can format all your code for you. I don't know about other IDE's though.
Back to top
View user's profile Send private message
Losplagos
Expert Cheater
Reputation: 0

Joined: 21 Mar 2006
Posts: 172
Location: Knee deep in a c++ book

PostPosted: Mon Aug 27, 2007 1:50 am    Post subject: Reply with quote

I was never good at sentence structure / puncation in school. So this is a hard part for me. And i did not know what || means because i never got a good enough description. I have got a few like this one
Quote:
This operation is performed between two bits (a and b). The result is 1 if either one of the two bits is 1, or if both are 1. If none is equal to 1 the result is 0.
Which is quite confusing. As soon as i am done i will post my late'st revision.
Edit four: Here is my indented code which is probly still wrong.
Code:
#include <iostream>
#include <cmath>
#define PI 3.14159
int main()
{
    std::cout << "Ok so enter a negetive number to exit the calculation program\n"
    << "This program calculates how far a gunbound shot will travel\n"
    << "There are your shot calculations\n Put in 0 to quit\n";
    for(double  g,b,v,u,r;;)
    {
        std::cout << "What is The gravity of your shot?: ";
        std::cin >> g;
        if (g==0) break;
        std::cout << "What is The angle of the shot?: ";
        std::cin >> b;
        if (b==0) break;
        std::cout << "What is the power of the shot in pixels?: ";
        std::cin >> v;
        if (v==0||v>400) break;
        u = (PI/180)*b;
        r = (v*v)*sin(2*u) / g;
        std::cout
        <<"Answer = "
        << r<<std::endl;
}
return EXIT_SUCCESS;
}

And thanks

_________________

Earthbound = 31337
Back to top
View user's profile Send private message
Display posts from previous:   
Post new topic   Reply to topic    Cheat Engine Forum Index -> General programming All times are GMT - 6 Hours
Goto page Previous  1, 2, 3
Page 3 of 3

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
You cannot attach files in this forum
You can download files in this forum


Powered by phpBB © 2001, 2005 phpBB Group

CE Wiki   IRC (#CEF)   Twitter
Third party websites