some help with my first C code

This is a discussion on some help with my first C code within the C Programming forums, part of the General Programming Boards category; Hi everyone, I am writing my first ever C code but it's quite different from the "easy to use" java ...

  1. #1
    Registered User
    Join Date
    Nov 2008
    Posts
    14

    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
    Last edited by Salem; 11-04-2008 at 10:26 AM. Reason: Snip Email Address

  2. #2
    Woof, woof! zacs7's Avatar
    Join Date
    Mar 2007
    Location
    Australia
    Posts
    3,459
    http://www.cprogramming.com/tools.html

    BTW, miracle C is terrible.
    Last edited by zacs7; 11-03-2008 at 11:29 PM.

  3. #3
    and the hat of wrongness Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    32,541
    Yeah, Miracle C is a PoS.

    http://www.codeblocks.org/downloads/5
    Then grab codeblocks-8.02mingw-setup.exe

    Of many many advantages, it is
    - functional
    - free
    - compliant with ANSI-C
    - used by many many people
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.
    I support http://www.ukip.org/ as the first necessary step to a free Europe.

  4. #4
    Registered User
    Join Date
    Nov 2008
    Posts
    14
    Quote Originally Posted by Salem View Post
    Yeah, Miracle C is a PoS.

    http://www.codeblocks.org/downloads/5
    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. #5
    C++まいる!Cをこわせ! Elysia's Avatar
    Join Date
    Oct 2007
    Posts
    22,604
    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
    Quote Originally Posted by Adak View Post
    io.h certainly IS included in some modern compilers. It is no longer part of the standard for C, but it is nevertheless, included in the very latest Pelles C versions.
    Quote Originally Posted by Salem View Post
    You mean it's included as a crutch to help ancient programmers limp along without them having to relearn too much.

    Outside of your DOS world, your header file is meaningless.

  6. #6
    Registered User
    Join Date
    Nov 2008
    Posts
    14
    Quote Originally Posted by Elysia View Post
    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. #7
    Banned master5001's Avatar
    Join Date
    Aug 2001
    Location
    Visalia, CA, USA
    Posts
    3,685
    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. #8
    Registered User
    Join Date
    Nov 2008
    Posts
    14
    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. #9
    Banned master5001's Avatar
    Join Date
    Aug 2001
    Location
    Visalia, CA, USA
    Posts
    3,685
    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. #10
    Registered User
    Join Date
    Nov 2008
    Posts
    10
    He wants an already compiled version of his code as an exe, as he is struggling with compilers.

  11. #11
    Registered User
    Join Date
    Nov 2008
    Posts
    14
    Quote Originally Posted by C/C++ Learner View Post
    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. #12
    Banned master5001's Avatar
    Join Date
    Aug 2001
    Location
    Visalia, CA, USA
    Posts
    3,685
    I have TurboC on a floppy somewhere....

  13. #13
    Registered User
    Join Date
    Jan 2007
    Location
    Euless, TX
    Posts
    144
    I ran your program using 20 terms and 8 digits --- both versions were well above 3.14

  14. #14
    Registered User
    Join Date
    Nov 2008
    Posts
    14
    Quote Originally Posted by kcpilot View Post
    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
    Last edited by skyt; 11-04-2008 at 12:35 PM.

  15. #15
    Registered User
    Join Date
    Nov 2008
    Posts
    14
    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,

Page 1 of 3 123 LastLast
Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Extended ASCII Characters in an RTF Control
    By JustMax in forum C Programming
    Replies: 18
    Last Post: 04-03-2009, 08:20 PM
  2. Enforcing Machine Code Restrictions?
    By SMurf in forum Tech Board
    Replies: 21
    Last Post: 03-30-2009, 07:34 AM
  3. Obfuscated Code Contest
    By Stack Overflow in forum Contests Board
    Replies: 51
    Last Post: 01-21-2005, 03:17 PM
  4. Interface Question
    By smog890 in forum C Programming
    Replies: 11
    Last Post: 06-03-2002, 05:06 PM
  5. Replies: 0
    Last Post: 02-21-2002, 05:05 PM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21