Go Back   CodingForums.com > :: Computing & Sciences > Computer Programming

Before you post, read our: Rules & Posting Guidelines

Reply
 
Thread Tools Rate Thread
Enjoy an ad free experience by logging in. Not a member yet? Register.
Old 09-25-2009, 06:30 AM   PM User | #1
Ultima-X97
New Coder

 
Join Date: Apr 2007
Posts: 37
Thanks: 3
Thanked 0 Times in 0 Posts
Ultima-X97 has a little shameless behaviour in the past
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
Ultima-X97 is offline   Reply With Quote
Old 09-25-2009, 08:03 AM   PM User | #2
Fou-Lu
God Emperor


 
Fou-Lu's Avatar
 
Join Date: Sep 2002
Location: Saskatoon, Saskatchewan
Posts: 15,654
Thanks: 4
Thanked 2,451 Times in 2,420 Posts
Fou-Lu is a name known to allFou-Lu is a name known to allFou-Lu is a name known to allFou-Lu is a name known to allFou-Lu is a name known to allFou-Lu is a name known to all
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?
__________________
As of PHP 5.5, the MySQL library has been officially deprecated. It is recommended to move to either MySQLi or PDO libraries for your mysql connectivity. See here for help choosing which interface you prefer: http://php.net/manual/en/mysqlinfo.api.choosing.php
Fou-Lu is offline   Reply With Quote
Old 09-25-2009, 01:14 PM   PM User | #3
Ultima-X97
New Coder

 
Join Date: Apr 2007
Posts: 37
Thanks: 3
Thanked 0 Times in 0 Posts
Ultima-X97 has a little shameless behaviour in the past
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.
Ultima-X97 is offline   Reply With Quote
Old 09-26-2009, 08:27 AM   PM User | #4
Fou-Lu
God Emperor


 
Fou-Lu's Avatar
 
Join Date: Sep 2002
Location: Saskatoon, Saskatchewan
Posts: 15,654
Thanks: 4
Thanked 2,451 Times in 2,420 Posts
Fou-Lu is a name known to allFou-Lu is a name known to allFou-Lu is a name known to allFou-Lu is a name known to allFou-Lu is a name known to allFou-Lu is a name known to all
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.
__________________
As of PHP 5.5, the MySQL library has been officially deprecated. It is recommended to move to either MySQLi or PDO libraries for your mysql connectivity. See here for help choosing which interface you prefer: http://php.net/manual/en/mysqlinfo.api.choosing.php
Fou-Lu is offline   Reply With Quote
Reply

Bookmarks

Jump To Top of Thread


Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT +1. The time now is 05:25 PM.


Advertisement
Log in to turn off these ads.