Ro0t
New Member
bla bla
Posts: 50
|
Post by Ro0t on Jun 15, 2003 10:16:35 GMT -5
Ah well, i'm new here and wanted to share my PI counting code ;D Maybe some of you find it interesting #include <stdio.h>
const PI = 3.1415927; int Number;
int main() { printf("The Power of PI and C\n-----------------\n\n"); printf("Number: "); scanf("%i",& Number); printf("%i x pi = %i",Number,Number * PI);
getchar(); getchar(); }
|
|
z00ey
New Member
return is the movement of sense..
Posts: 2,309
|
Post by z00ey on Jun 15, 2003 10:22:59 GMT -5
yep.. welcome here, any source is interesting for someone
..but it doesn t count pi (or am i confused cause of the c code , i m used to c++ ?)
|
|
Ro0t
New Member
bla bla
Posts: 50
|
Post by Ro0t on Jun 15, 2003 10:33:25 GMT -5
Basicly what is does br]1. Give the variable PI the PI integer :P 2. Ask for a input to increaseit with 3. Give back the anwser ;D
|
|
z00ey
New Member
return is the movement of sense..
Posts: 2,309
|
Post by z00ey on Jun 15, 2003 10:35:43 GMT -5
yep, that s what i thought.. ..just thought first you were talking about counting the digits after the comma when i saw "counting PI"
(like: number of digits to display: ? etc )
|
|
Trad
New Member
Posts: 1,122
|
Post by Trad on Jun 15, 2003 11:55:06 GMT -5
cool, yeah we always like sources and other activity besides our own in this forum im not used to the stdio i/o. and i dont know what scanf() does, ill have to look it up. and is it C code? or C++, it looks like c++ but the topic says C, so im confused.
|
|
Trad
New Member
Posts: 1,122
|
Post by Trad on Jun 15, 2003 11:56:35 GMT -5
p.s it should be void main(), main doesnt return a value.
|
|
Ro0t
New Member
bla bla
Posts: 50
|
Post by Ro0t on Jun 15, 2003 12:09:23 GMT -5
It's all C code, and it works fine 4 me I have a book about programming in C and everything i learn i'll place it on this forum, other people plearn 4 free with me ;D And i have something to check if i have forgoten I don't see the difference between void main() {} and int main {} Maybe you can explain
|
|
|
Ro0t
New Member
bla bla
Posts: 50
|
Post by Ro0t on Jun 15, 2003 12:23:50 GMT -5
Thnx, i'm getting smart by you guys
|
|
Trad
New Member
Posts: 1,122
|
Post by Trad on Jun 15, 2003 12:25:11 GMT -5
its as much c++ as it is c
|
|
Trad
New Member
Posts: 1,122
|
Post by Trad on Jun 15, 2003 12:29:18 GMT -5
oh yeah, before any function you need to declare the type it returns, ie
char returnachar() { char mychar = a; return a; }
int return_number() { int number = 5; return number; }
void means it doesnt return anything, and in your code, main() doesnt return anything and should be void.
|
|
z00ey
New Member
return is the movement of sense..
Posts: 2,309
|
Post by z00ey on Jun 15, 2003 12:35:33 GMT -5
its as much c++ as it is c ..of course, just because c++ is "downstairs" compatible, lol (you can compile every c code with c++) but it would be pretty silly to use c code with a c++ compiler (printf is not documented in c++ because there are much better ways to handle the input output) ..that s what i meant.. ..it s not c++ code but it can be compiled with c++
btw: same with the ugly .h ..you can use it in c++ because you must use it with c.. ..but it s not necessary, "pure" c++ code would be #include <stdio> eg
|
|
Trad
New Member
Posts: 1,122
|
Post by Trad on Jun 15, 2003 12:44:47 GMT -5
z00ey i think you got the wrong perspective on this.
you cant say
#include <stdio> is c++ code and #include <stdio.h> is C code
C++ = C + More advanced things
everything available in C is available in C++. its all the same code (C++) just its a lot more advanced and there is more than one way to do things.
|
|
z00ey
New Member
return is the movement of sense..
Posts: 2,309
|
Post by z00ey on Jun 15, 2003 12:59:29 GMT -5
nope, lol.. ..don t want to break up an argument, but exactly like i said
..the only reason why you can compile c code with c++ is to make it easier for ppl who learned/grew up with c to "step" up.. ..it s nonsense to teach someone who begins (using c++) c-code..
..and #include <stdio> is c++ code and #include <stdio.h> is c code that can be compiled with c++ too (like printf and all the other stuff, no c++ code, but can be compiled with )
|
|
Trad
New Member
Posts: 1,122
|
Post by Trad on Jun 15, 2003 13:54:06 GMT -5
Ok i see your point now
|
|