...

View Full Version : A problem with while looping



Ultima-X97
09-25-2009, 06:30 AM
Why wont this loop correctly?



#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

Fou-Lu
09-25-2009, 08:03 AM
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?

Ultima-X97
09-25-2009, 01:14 PM
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.

Fou-Lu
09-26-2009, 08:27 AM
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.



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum