Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 4 of 4
  1. #1
    New Coder
    Join Date
    Apr 2007
    Posts
    37
    Thanks
    3
    Thanked 0 Times in 0 Posts

    A problem with while looping

    Why wont this loop correctly?

    Code:
    #define _CRT_SECURE_NO_WARNING
    #include <stdio.h>
    void main(void)
    {
    	float ini,fin,inc,x;
    	printf("Enter initial value: ");
    	scanf("%f",&ini);
    	printf("Enter final value: ");
    	scanf("%f",&fin);
    	printf("Enter increment value: ");
    	scanf("%f",&inc);
    	
    	while (ini<=fin)
    	{
    		printf("%5f\n",&ini);
    		ini=ini+inc;
    	}
    
    
    
    
    
    
    	printf("Look at what you have"); //ignore these lines, I made this just 
    	scanf("%f",&ini); //                     keep the cmd from closing  
    }
    I put in 30,100, and 10 respectively and all it does it give me eight rows of 0.000000 when it should give me:

    30.000
    40.000
    50.000
    60.000
    70.000
    80.000
    90.000
    100.000

  • #2
    God Emperor Fou-Lu's Avatar
    Join Date
    Sep 2002
    Location
    Saskatoon, Saskatchewan
    Posts
    16,979
    Thanks
    4
    Thanked 2,659 Times in 2,628 Posts
    Printf doesn't want pointers (except for char*), it wants de-referenced values. Just give it you're ini variable, not the address of it (ie: not &ini).
    What you would print otherwise would be the hex address for it, but my guess is that the closest representation of the hex address in the float would be zero.

    I assume this is for an assignment, have you not covered memory mapping in any way?
    PHP Code:
    header('HTTP/1.1 420 Enhance Your Calm'); 

  • #3
    New Coder
    Join Date
    Apr 2007
    Posts
    37
    Thanks
    3
    Thanked 0 Times in 0 Posts
    Well this isn't for any sort of assignment. I am a web designer and I have took a great interest in C after my friend who is a college professor showed me how to make a few programs and now he is teach me. I am not to familiar with memory mapping.

  • #4
    God Emperor Fou-Lu's Avatar
    Join Date
    Sep 2002
    Location
    Saskatoon, Saskatchewan
    Posts
    16,979
    Thanks
    4
    Thanked 2,659 Times in 2,628 Posts
    Quote Originally Posted by Ultima-X97 View Post
    Well this isn't for any sort of assignment. I am a web designer and I have took a great interest in C after my friend who is a college professor showed me how to make a few programs and now he is teach me. I am not to familiar with memory mapping.
    Eh, that will be tough to explain datatypes and memory types (static, stack and heap).
    You may want to get you're friend to illustrate it, especially if you're unfamiliar with lower level languages like C.
    PHP Code:
    header('HTTP/1.1 420 Enhance Your Calm'); 


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •