473,320 Members | 1,896 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,320 software developers and data experts.

"For" not functionning

Hello.
I'm a complete beginner and I cant go through the third exercise of my book
;-(((
I wrote :
#include <stdio.h>

main()
{
int fahr;
for (fahr = 300; fahr <= 0; fahr = fahr - 20)
printf("%3d %6.1f\n", fahr, (5.0/9.0)*(fahr-32));
}

There is no output. The reverse (from 0 to 300) is OK.
I'm using MinGW with windows XP.

What's wrong ?
Thanks in advance.
Daniel
Mar 2 '08 #1
4 1259

"Daniel.C" <dc*************@free.frwrote in message
news:47***********************@news.free.fr...
Hello.
I'm a complete beginner and I cant go through the third exercise of my
book ;-(((
I wrote :
#include <stdio.h>

main()
{
int fahr;
for (fahr = 300; fahr <= 0; fahr = fahr - 20)
printf("%3d %6.1f\n", fahr, (5.0/9.0)*(fahr-32));
Try fahr>=0

--
Bart

Mar 2 '08 #2
In article <47***********************@news.free.fr>, "Daniel.C" <dc*************@free.frwrote:
>Hello.
I'm a complete beginner and I cant go through the third exercise of my book
;-(((
I wrote :
#include <stdio.h>

main()
{
int fahr;
for (fahr = 300; fahr <= 0; fahr = fahr - 20)
printf("%3d %6.1f\n", fahr, (5.0/9.0)*(fahr-32));
}

There is no output. The reverse (from 0 to 300) is OK.
I'm using MinGW with windows XP.

What's wrong ?
What's wrong is that the second part of a for statement ( fahr <= 0, in this
case) specifies the condition under which the loop is to continue running.
You've told it to start out with fahr = 300, and subtract 20 from it,
continuing for as long as the value of fahr is less than or equal to zero.

Of course, fahr is already greater than zero when you start, so the condition
under which the loop is to continue running is already false from the very
beginning -- and the loop never executes.

It appears to me that you've misunderstood the second part as specifying the
condition under which the loop is to stop. That's not the case.

--
Regards,
Doug Miller (alphageek at milmac dot com)

It's time to throw all their damned tea in the harbor again.
Mar 2 '08 #3
"Doug Miller" <sp******@milmac.coma écrit dans le message de news:
Df******************@newssvr21.news.prodigy.net...
In article <47***********************@news.free.fr>, "Daniel.C"
<dc*************@free.frwrote:
>>Hello.
I'm a complete beginner and I cant go through the third exercise of my
book
;-(((
I wrote :
#include <stdio.h>

main()
{
int fahr;
for (fahr = 300; fahr <= 0; fahr = fahr - 20)
printf("%3d %6.1f\n", fahr, (5.0/9.0)*(fahr-32));
}

There is no output. The reverse (from 0 to 300) is OK.
I'm using MinGW with windows XP.

What's wrong ?

What's wrong is that the second part of a for statement ( fahr <= 0, in
this
case) specifies the condition under which the loop is to continue running.
You've told it to start out with fahr = 300, and subtract 20 from it,
continuing for as long as the value of fahr is less than or equal to zero.

Of course, fahr is already greater than zero when you start, so the
condition
under which the loop is to continue running is already false from the very
beginning -- and the loop never executes.

It appears to me that you've misunderstood the second part as specifying
the
condition under which the loop is to stop. That's not the case.

--
Regards,
Doug Miller (alphageek at milmac dot com)

It's time to throw all their damned tea in the harbor again.
Many thanks too. I understood it the wrong way. I'm improving myself ;-)))
Daniel
Mar 2 '08 #4
Daniel.C wrote:
[...]
for (fahr = 300; fahr <= 0; fahr = fahr - 20)
^^^
That's backwards. fahr is never less than 0/
[...]
Mar 2 '08 #5

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

23
by: Invalid User | last post by:
While trying to print a none empty list, I accidentaly put an "else" statement with a "for" instead of "if". Here is what I had: if ( len(mylist)> 0) : for x,y in mylist: print x,y else:...
3
by: Phil | last post by:
Hi everybody, I am a XSLT beginner and the following problem really makes me crazy ! I have a main "contacts.xml" document which contains references to several contact data XML files. My aim...
27
by: Curious Angel | last post by:
I have a resume in PDF format and I want anyone who LEFT-OR-RIGHT clicks the link to force the file to be saved, and in any event _not_ opened. Since the PDF will be in his cache in any event, I...
1
by: putty | last post by:
I found a few posts of people asking about insertCell()/insertRow() not working in IE6 SP2, and a few others about getting "null is null or not an object" errors, but no one posted a solution...
8
by: Lian | last post by:
Hi all, It is a newbie's question about html tag "img". The attributes "title" and "alt" for "img" seems having the same function. So what is the main difference between them? Can i use them at...
4
by: John Devereux | last post by:
Hi, I would like some advice on whether I should be using plain "chars" for strings. I have instead been using "unsigned char" in my code (for embedded systems). In general the strings contain...
1
by: Erialc Berts | last post by:
I know why we get this error, but does anyone know how to catch it so that we can display a more helpful message to our users? I am interested both in a .exe and a web site. Thanks in advance...
0
by: Kevin Mitchell | last post by:
I have an NT shared hosting account, but the provider names the script/write folder cgi-bin. I want to place DLLs in the cgi-bin directory and get them to work in my Web applications. What do I...
2
by: marsarden | last post by:
write code like: int main(void) { int a=10; if(a<20) {} } Compiler ok on dev-cpp . don't we have to add a ";" after if
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.