- Joined
- Apr 12, 2004
- Messages
- 1,101
- Reaction score
- 0
...
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.
You must be trolling. Read a book, like "The C Programming Language" by Kernighan and Ritchie.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..
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.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 -.-
Use function prototypes. Period.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.
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.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.
#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.
Add to the top:
using namespace std;
#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());
}
program
|
code-------+
code |-----+
code ------+ |
code------------+