for loop problems

This is a discussion on for loop problems within the C Programming forums, part of the General Programming Boards category; hey guys can some one look over my code....it wont compile im using miracle c...can you guys tell me if ...

  1. #1
    Registered User
    Join Date
    Feb 2008
    Posts
    30

    for loop problems

    hey guys can some one look over my code....it wont compile im using miracle c...can you guys tell me if its the code or the compiler....thanks

    Code:
    #include <stdio.h>
    #include <math.h>
    
    
    int main()
    {
    
    	/* declared variable*/
    	int a;
    	int b;
    	int c;
    	int d;
    	
    	
    	for(a = 1; a <= 7; a++) // will increment by 1 until 7 is reached
    	{
    		printf("%d/n", a); //will print out result
    	}
    	
    	
    	for(b = 1; b <= 23; b += 5)
    	{
    		printf("%d/n", b);
    	}
    	
    	for(c = 20; c >= -10; c -= 6)
    	{
    		printf("%d/n", c);
    	}
    		
    	for(d = 19; d <= 51; d += 8)
    	{
    		printf("%d/n", d);
    	}
    	
    	
    	getch();
    	return 0;
    	
    }

  2. #2
    C++ Witch laserlight's Avatar
    Join Date
    Oct 2003
    Location
    Singapore
    Posts
    21,915
    What are the compile errors?

    It looks fine, except that you probably should use /* */ style comments instead of // style comments, and getchar() instead of getch().
    C + C++ Compiler: MinGW port of GCC
    Version Control System: Bazaar

    Look up a C++ Reference and learn How To Ask Questions The Smart Way

  3. #3
    Registered User
    Join Date
    Feb 2008
    Posts
    30
    there are no compile errors it just wont compile....is there a free c compiler out there?? thats better then miracle c?

  4. #4
    C++ Witch laserlight's Avatar
    Join Date
    Oct 2003
    Location
    Singapore
    Posts
    21,915
    there are no compile errors it just wont compile....
    Have you ever gotten it to compile before?

    is there a free c compiler out there?? thats better then miracle c?
    You can use g++ (or its MinGW port on Windows) or the compiler from Visual C++ Express.
    C + C++ Compiler: MinGW port of GCC
    Version Control System: Bazaar

    Look up a C++ Reference and learn How To Ask Questions The Smart Way

  5. #5
    Registered User
    Join Date
    Feb 2008
    Posts
    30
    i fixed the ch to char it ran and its good now thanks

  6. #6
    Dr Dipshi++ mike_g's Avatar
    Join Date
    Oct 2006
    Location
    On me hyperplane
    Posts
    1,218
    Yes, try: dev c++, visual studio express, or code blocks.

    Also, getch() should be getchar(). Maybe that would get it to work? Although your compiler should say something about it.

  7. #7
    Registered User
    Join Date
    Feb 2008
    Posts
    30
    it did work i have dev c++ but i dont know how to compile c programs in it...i would write the code save it as a c file but it wont compile or anything....and i have to put getchar at the end of the file because i run in vista and the dos window wont stay up

  8. #8
    Technical Lead QuantumPete's Avatar
    Join Date
    Aug 2007
    Location
    London, UK
    Posts
    894
    Quote Originally Posted by clezzie View Post
    an you guys tell me if its the code or the compiler.
    99.999% of the time it's the code

    QuantumPete
    "No-one else has reported this problem, you're either crazy or a liar" - Dogbert Technical Support
    "Have you tried turning it off and on again?" - The IT Crowd

  9. #9
    Registered User slingerland3g's Avatar
    Join Date
    Jan 2008
    Location
    Seattle
    Posts
    603
    Also I am sure you meant to place a new line? Good call on using getchar

    use this

    Code:
    printf("%d\n", b);

    Also not sure why you need the getchar() here?

  10. #10
    Registered User
    Join Date
    Feb 2008
    Posts
    26
    getchar() is what keeps the command line window from disappearing at the end of program execution.

    Also, you not not need the math header file in the code.

  11. #11
    Registered User
    Join Date
    Mar 2008
    Posts
    5
    Prefer using "/* */" for comments instead of "//" in ANSI standart it is not acceptable.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. No clue how to make a code to solve problems!
    By ctnzn in forum C Programming
    Replies: 8
    Last Post: 10-16-2008, 02:59 AM
  2. C Pointers Problems
    By mhelal in forum C Programming
    Replies: 8
    Last Post: 01-10-2007, 05:35 AM
  3. String Manipulation problems -_-
    By Astra in forum C Programming
    Replies: 5
    Last Post: 12-13-2006, 04:48 PM
  4. Rendering problems (DirectX?)
    By OnionKnight in forum Tech Board
    Replies: 0
    Last Post: 08-17-2006, 12:17 PM
  5. DJGPP problems
    By stormswift in forum C Programming
    Replies: 2
    Last Post: 02-26-2002, 03:35 PM

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