Wrox Programmer Forums
|
C++ Programming General discussions for the C++ language. For questions specific to Microsoft's Visual C++ variant, see the Visual C++ forum instead.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the C++ Programming section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
  #1 (permalink)  
Old September 15th, 2006, 04:52 AM
Registered User
 
Join Date: Sep 2006
Posts: 1
Thanks: 0
Thanked 0 Times in 0 Posts
Default i want ur help! thanx!

i'm a beginner in c field, and i meet a problem i can't understand why and how to occur that.
my code as follow:
#include <iostream.h>
#include <stdio.h>
void main()
{
 int a;
 scanf("%d\n", &a);
 printf("wut u get from the console is: %d", a);
}

when i add '\n' in scanf function as you see before, it can't work as i hope. why? and how? thanx!



Reply With Quote
  #2 (permalink)  
Old September 18th, 2006, 11:33 AM
Authorized User
 
Join Date: Jul 2006
Posts: 15
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Hi,

what do you expect to see if you haven't initialised the variable "a".
what you need to do to see anything is initialise "a".

Hope this helps.
wambozi.

Reply With Quote
  #3 (permalink)  
Old September 18th, 2006, 03:04 PM
Authorized User
 
Join Date: Mar 2006
Posts: 21
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via MSN to skoob1152 Send a message via Yahoo to skoob1152
Default

I hope you are kidding (wambozi) do you know what is scanf function?
I think you don't, but you will learn some day I hope.

Here is your answer vincentaries, you are declaring "a" as int, but you are using: scanf("% "d" \n", &a); %d this is four double not for int so try this: scanf("%lf\n", &a); this shoud resolve you'r problem;)

PD. you can use the %lf and save it in double variable but not vise-verse.

Reply With Quote





Similar Threads
Thread Thread Starter Forum Replies Last Post
can anybody share ur knowledge wth ajax kunchala_rakesh Ajax 1 September 13th, 2007 10:10 PM
Need ur help anils Visual Basic 2005 Basics 0 May 27th, 2007 02:55 AM
Need ur help anils Visual Basic 2005 Basics 0 May 27th, 2007 02:53 AM
im new here and i need ur help.... momoi Beginning VB 6 2 January 30th, 2006 11:44 PM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.