Welcome!

Join our community of MMO enthusiasts and game developers! By registering, you'll gain access to discussions on the latest developments in MMO server files and collaborate with like-minded individuals. Join us today and unlock the potential of MMO server development!

Join Today!

[C++] My First Program =]

Status
Not open for further replies.
Custom Title Activated
Loyal Member
Joined
Apr 12, 2004
Messages
1,101
Reaction score
0
I started learning C++ 2 days ago. I've been learning by looking at examples.

So far, I've made a command line calculator. Check it out and lemme know what you think. It could probably help out other people who are new to programming.

There is a problem though, it seems to require something non-standard in order to run.. I'm not sure what that something is.. but my computer has it.

Name:
Calculatizor
Source:
Download:

Screenshot:
 
Divine Celestial
Loyal Member
Joined
Jul 7, 2004
Messages
853
Reaction score
5
sage

...

I'll be interested once you write a calculator that can evaluate 358+67*17-2/(6-4)+8.

And WTF is with all the gotos? Have you been learning C++ by looking at Asm code?

srsly, your code is awful. The flow is convoluted.
 
Junior Spellweaver
Loyal Member
Joined
Mar 25, 2007
Messages
174
Reaction score
0
Only thing that amkes it half-decent is that it;s your first one, but don't overuse the goto. Very irritating.
 
Custom Title Activated
Loyal Member
Joined
Apr 12, 2004
Messages
1,101
Reaction score
0
Re: sage

...

I'll be interested once you write a calculator that can evaluate 358+67*17-2/(6-4)+8.

And WTF is with all the gotos? Have you been learning C++ by looking at Asm code?

srsly, your code is awful. The flow is convoluted.

Lol, what more did you expect? Anyway, I did that because I couldn't figure out how to get other functions to work... If I put the other functions after main(), then I can't use them in main(), cause they haven't been defined yet. And if I put them before main(), they will execute, but then main() won't execute, it will just be skipped.. and I can't tell each function to go to the next one, cause the next one hasn't been defined yet.

I'm sure there's probably a better solution to this, but I figured goto worked as a temporary solution.

I don't see how it's convoluted though.. I tried to make it very easy to add more functions to choose from, and able to be used in different programs without a whole lot needing to be changed.
 
Divine Celestial
Loyal Member
Joined
Jul 7, 2004
Messages
853
Reaction score
5
sage

Lol, what more did you expect? Anyway, I did that because I couldn't figure out how to get other functions to work... If I put the other functions after main(), then I can't use them in main(), cause they haven't been defined yet. And if I put them before main(), they will execute, but then main() won't execute, it will just be skipped..
You must be trolling. Read a book, like "The C Programming Language" by Kernighan and Ritchie.

If this is real, I suggest you stop writing any further programs until you've read that book -.-
 
All is well...
Loyal Member
Joined
Feb 22, 2006
Messages
1,520
Reaction score
0
Re: sage

You must be trolling. Read a book, like "The C Programming Language" by Kernighan and Ritchie.

If this is real, I suggest you stop writing any further programs until you've read that book -.-
I personally have more fun learning it by myself. It's more entertaining to just go to one of those sites that lists functions and snippets and what not and learn from those. Sure you don't get the full experience but you learn as you go and when you figure something out it seems much more meaningful.

But you know more than I do that's for sure. Kudos =p
Wh005h knows little to none in C++
 
Divine Celestial
Loyal Member
Joined
Jul 7, 2004
Messages
853
Reaction score
5
sage



No comment.
 
Junior Spellweaver
Loyal Member
Joined
Mar 25, 2007
Messages
174
Reaction score
0
Re: sage

Lol, what more did you expect? Anyway, I did that because I couldn't figure out how to get other functions to work... If I put the other functions after main(), then I can't use them in main(), cause they haven't been defined yet. And if I put them before main(), they will execute, but then main() won't execute, it will just be skipped.. and I can't tell each function to go to the next one, cause the next one hasn't been defined yet.
Use function prototypes. Period.
What compiler are you using? A hand made one no doubt that's barely done. In fact, I'll rewrite this program when I get the time to show you how it's done.
 
Custom Title Activated
Loyal Member
Joined
Apr 12, 2004
Messages
1,101
Reaction score
0


That compiled perfectly fine.

Thanks for the effort. I'll check that out right away.

And username1, no I'm not trolling.

I completely agree with what wh005h said. Trial and error > reading books to learn. I don't need to be told to RTFM, I'm doing that already. I enjoy trying to get as much done as possible with the little snippets of code I understand, then looking at more code and finding new stuff, figuring out what it does and how to use it properly.

Of course this program is gonna be god awfull. It was a historical moment for me because I finally got the program to do what I wanted it to do without any major problems. I posted the code as soon as it worked properly and compiled without error. That doesn't mean it's done. Doesn't even mean I think it's a good, or even a decent program.
 
Divine Celestial
Loyal Member
Joined
Jul 7, 2004
Messages
853
Reaction score
5
sage

I completely agree with what wh005h said. Trial and error > reading books to learn. I don't need to be told to RTFM, I'm doing that already.
Apparently you DO need to RTFM moar, as you completely failed at understanding the concept of program flow and how it's done in C, as evidenced by your quote above. This is a perfect example of why you *must* read the books. No exceptions.

Here's an expression evaluator that *can* parse something like 3+5*10-200/(175*2)+45, and it also illustrates the proper use of goto:
Code:
#define P(a,b) (*p==a||*p==b)
#define D (d?m/n:m*n)
char *p;
long r(){
 long a=0,m=1,n=0,d=0,e=1;

a:
 *p-=40;
 if P(3,5) {
  if(e) m*=4-*p;
  else a+=D,n=0,m=4-*p,d=0,e=1;
  p++;
  goto a;
 }
 if P(2,7) {
  m=D;n=0;d=*p-2;e=1;
  p++;
  goto a;
 }
 e=0;
 if(!*p) {
  p++;
  n=r();
  p++;
  goto a;
 }
 if(*p-1&&*p+40) {
  n=n*10+*p-8;
  p++;
  goto a;
 }
 return a+D;
}

main(int c,char**v) {
 p=v[1];
 printf("%ld",r());
}
Umm... not much better. Trades the use of goto with excessive whitespace and needless use of an array.
 
Custom Title Activated
Loyal Member
Joined
Apr 12, 2004
Messages
1,101
Reaction score
0
Re: sage

Code:
#define P(a,b) (*p==a||*p==b)
#define D (d?m/n:m*n)
char *p;
long r(){
 long a=0,m=1,n=0,d=0,e=1;

a:
 *p-=40;
 if P(3,5) {
  if(e) m*=4-*p;
  else a+=D,n=0,m=4-*p,d=0,e=1;
  p++;
  goto a;
 }
 if P(2,7) {
  m=D;n=0;d=*p-2;e=1;
  p++;
  goto a;
 }
 e=0;
 if(!*p) {
  p++;
  n=r();
  p++;
  goto a;
 }
 if(*p-1&&*p+40) {
  n=n*10+*p-8;
  p++;
  goto a;
 }
 return a+D;
}

main(int c,char**v) {
 p=v[1];
 printf("%ld",r());
}

Thanks username1, This code is really helpful. :)
Btw I am RTFM'ing.
 
Custom Title Activated
Loyal Member
Joined
Sep 28, 2005
Messages
1,226
Reaction score
66
well normally you never have a reason to use goto :S
 
Newbie Spellweaver
Joined
Jan 25, 2007
Messages
44
Reaction score
0
very bad programmed
you know they call the goto commanad as
macarony spachity
beacuse it make the program like that
Code:
                                              program
                                                  |
                                                code-------+
                                                code      |-----+
                                                code ------+    |
                                                 code------------+
which means after he make the program if he want to update he wont be able beacuse he wont see how the program works beacuse fo these got commands
and second it is an asm code
which = low language
 
Supreme Arcanarch
Loyal Member
Joined
Mar 23, 2007
Messages
931
Reaction score
10
OMGLOL, a calculator. Nice man! We all started of this. :)
 
Newbie Spellweaver
Joined
Sep 2, 2007
Messages
12
Reaction score
0
Just friggen google it!

Anyway, you should have created a better program.
You have posted over 1000 post.
Like come on.

Atleast make it decent.
 
Custom Title Activated
Loyal Member
Joined
Jun 28, 2007
Messages
2,986
Reaction score
3
Since when does post count relates to programming knowledge? This forum has other sections like games, art and servers. Its not dedicated to coding...
 
Banned
Banned
Joined
Sep 29, 2006
Messages
164
Reaction score
0
Ok i just started attempting to learn c++ yesterday...

And let me tell ya, due to all these not so nice posts i will probably never stick anything in this showcase lol.
 
Status
Not open for further replies.
Back
Top