Path: csiph.com!x330-a1.tempe.blueboxinc.net!usenet.pasdenom.info!news.dougwise.org!nntpfeed.proxad.net!proxad.net!feeder1-2.proxad.net!74.125.64.80.MISMATCH!postnews.google.com!news2.google.com!Xl.tags.giganews.com!border1.nntp.dca.giganews.com!nntp.giganews.com!local2.nntp.dca.giganews.com!nntp.earthlink.com!news.earthlink.com.POSTED!not-for-mail NNTP-Posting-Date: Sun, 26 Jun 2011 01:06:09 -0500 Message-ID: <4E06CC51.5204@mindspring.com> Date: Sun, 26 Jun 2011 02:06:09 -0400 From: pete Reply-To: pfiland@mindspring.com Organization: PF X-Mailer: Mozilla 3.04Gold (WinNT; I) MIME-Version: 1.0 Newsgroups: comp.lang.c Subject: Re: printf & scanf order References: <88abc4aa-ecdb-4136-98a8-112a78916d6e@28g2000pry.googlegroups.com> Content-Type: text/plain; charset=us-ascii Content-Transfer-Encoding: 7bit Lines: 71 X-Usenet-Provider: http://www.giganews.com NNTP-Posting-Host: 4.154.219.253 X-Trace: sv3-XyoxYD7MWImbgVZ0RkUU2ggZuMziRQbvBu7HnqpWW4UZIFXU782h6gKT47/CWTe/GGhh6cxy2TXNwFy!zYkSCAwHvQa1fmZkXcW6jrX7c879rHlhep+U8whYwzAIoTgzYuUvasjpHeR34gpGXDTw8+7KPNza!Xo4Z9GdrD28= X-Abuse-and-DMCA-Info: Please be sure to forward a copy of ALL headers X-Abuse-and-DMCA-Info: Otherwise we will be unable to process your complaint properly X-Postfilter: 1.3.40 X-Original-Bytes: 2761 Xref: x330-a1.tempe.blueboxinc.net comp.lang.c:6957 flebber wrote: > > Hi > > I am starting to learn c and have been playing with several simple > scripts to learn. > > Question why does the request for scanf precede printf. I created a > simple script to calculate interest. When running the script though > scanf is processed first and the request for input comes first, > despite being in the second position. How do I get printf to call > first. > > This is my script. > > # include > int main() > { > float a,b,c,interest; > printf("Type in amount in dollars cents: \n"); > scanf("%f",&a); > b = 0.075; > c = a * b; > interest = a + c; > printf("The total including interest is $%.2f", interest); > return 0; > } I'm not sure if I understand your question. But if I do, then maybe placing fflush(stdout); before your scanf call might solve your problem. Also, it is best to terminate a text stream with a newline character in your last printf call. # include int main(void) { float a, b, c, interest; printf("Type in amount in dollars cents: \n"); fflush(stdout); scanf("%f",&a); b = 0.075f; c = a * b; interest = a + c; printf("The total including interest is $%.2f\n", interest); return 0; } (double) is a more natural type than (float). (double) is not subject to default argument promotions. # include int main(void) { double a, b, c, interest; printf("Type in amount in dollars cents: \n"); fflush(stdout); scanf("%lf",&a); b = 0.075; c = a * b; interest = a + c; printf("The total including interest is $%.2f\n", interest); return 0; } -- pete