[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: Nopaste - 6/8/07
Download: http://gregith.googlepages.com/calculatizor.rar

Screenshot:
http://gregith.googlepages.com/clcsreeeny.PNG
 
Only thing that amkes it half-decent is that it;s your first one, but don't overuse the goto. Very irritating.
 
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.
 
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 -.-
 
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++
 
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.
 
Nopaste - No description

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.
 
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.
 
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.
 
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
 
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.
 
Since when does post count relates to programming knowledge? This forum has other sections like games, art and servers. Its not dedicated to coding...
 
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