# Thread: some help with my first C code

1. ## some help with my first C code

Hi everyone, I am writing my first ever C code but it's quite different from the "easy to use" java that I knew better. I first wrote the code in java then basically converted word for word into C using some online resources and a book. (I used notepad for this). Here is my .c code and I have no idea what to do next
Code:
```#include <stdio.h>
#include <math.h>

int main(void){
int digit;
int approximation;
int cont = 1;
double pi = 0.0;
int method;
while(cont == 1){

printf("Please enter the number of terms of the series: ");
scanf("&#37;d", &approximation);
printf("Please enter the number of significant digit you wish to see: ");
scanf("%d", &digit);
printf("Which approximation would you like to use? Please enter the corresponding number (1 or 2): ");
scanf("%d", &method);
if(method == 1){
int i;
for(i = 1; i <= approximation; i++){
pi += 4*pow(-1, i+1)/(2*i-1);
}
printf("pi = %2.*f\n", digit-1, pi);
}

if(method == 2){
int i;
for(i = 1; i <= approximation; i++){
pi += pow(12, 0.5)*pow(-1, i+1)/((2*i - 1)*(pow(3, i-1)));
}
printf("pi = %2.*f\n", digit-1, pi);
}
printf("Would you like to run this program again? (1 for Yes, 0 for No)");
scanf("%d", &cont);
if(cont != 1) printf("Thank you, come again!");
}
return 0;
}```
This code basically askes the user to input 3 integers and approximate pi using 2 methods (2 series). I tried to compile it with miracle C but the result was not desired. Can someone help a poor noob? Please tell me what software I need to download, and the exact steps. Thanks

2. http://www.cprogramming.com/tools.html

BTW, miracle C is terrible.

3. Yeah, Miracle C is a PoS.

Then grab codeblocks-8.02mingw-setup.exe

Of many many advantages, it is
- functional
- free
- compliant with ANSI-C
- used by many many people

4. Originally Posted by Salem
Yeah, Miracle C is a PoS.

Then grab codeblocks-8.02mingw-setup.exe

Of many many advantages, it is
- functional
- free
- compliant with ANSI-C
- used by many many people
I downloaded this and pasted my code into it, but when I try to build a .exe from the code by control F9, it gives me
"pi - Debug" uses an invalid compiler. Skipping...
Nothing to be done.
what should i do, is there something wrong with my code?

5. Lucky to say, it is simply a misconfiguration in the IDE. How to fix it, I do not know; I, myself, do not use Code::Blocks. But rest assured that it is not your code that is faulty.
There are other alternatives too, if you wish to look: http://cpwiki.sf.net/IDE

6. Originally Posted by Elysia
Lucky to say, it is simply a misconfiguration in the IDE. How to fix it, I do not know; I, myself, do not use Code::Blocks. But rest assured that it is not your code that is faulty.
There are other alternatives too, if you wish to look: http://cpwiki.sf.net/IDE
good to hear that my code is fine, but i tried about 5 different IDE and yet i still do not have an excuable. this is driving me crazy...im gonna try eclipse now

7. It sounds to me like the problem lies between the desk and the chair and that perhaps learning how to configure an IDE is beneficial to anyone who is planning on writing code. Personally, my cat walking around on my keyboard has resulted in configuration change or two in the past.

8. can someone excute this for me and email me the .exe, i know i should trust the people i dont know's exe files but im desperate..

9. What exe are you wanting emailed to you? And you would be wise to post the username of whoever sends you the exe so that one of the regulars here can tell you whether or not to trust the source.

10. He wants an already compiled version of his code as an exe, as he is struggling with compilers.

11. Originally Posted by C/C++ Learner
He wants an already compiled version of his code as an exe, as he is struggling with compilers.
yea, that's exactly what i want. maybe for one of you it's a few click of button but for me, i've been stuck with this since yesterday.

12. I have TurboC on a floppy somewhere....

13. I ran your program using 20 terms and 8 digits --- both versions were well above 3.14

14. Originally Posted by kcpilot
I ran your program using 20 terms and 8 digits --- both versions were well above 3.14
well 20 terms are not sufficient to give an accurate pi value, you need to use at least over 1000 terms

and strange, when i do it, first method should give 3.09 and 2nd method should give 3.14 something

15. never mind all, i finally pushed myself to learn borland and got the config set up, now the code is running but there's a few errors that i have to fix, thanks for all the help,