GIDForums  

Go Back   GIDForums > Computer Programming Forums > C Programming Language
User Name
Password
Register FAQ Members List Calendar Search Today's Posts Mark Forums Read

 
 
Thread Tools Search this Thread Rate Thread
  #1  
Old 17-Nov-2003, 16:08
gmn gmn is offline
Junior Member
 
Join Date: Aug 2003
Posts: 33
gmn is on a distinguished road
Question

i/o: set value x (long) before it is used by a function


hopefully this will be an easy one for somebody.......

i can get this working using c++ but not with c (which i never learnt) and i need this as part of an assignment. my problem is that i cant seem to make scanf behave line cin, all i want is for the user to set value x (long) before it is used by a function. function works fine if the value is entered directly into the code.

heres the bit i mean,
CPP / C++ / C Code:
double factorial(double  n);
double power(double a, double b);
double doSine(double x);

double x;

printf("to run sin(x) function please enter value x: ");
scanf("%f", &x);

printf("\n%f", x); //at this point x is always some huge negative
//number, and if i initialise x above it retains its value regardless
//of scanf (being run as console app.)

printf("factorial of x is %f\n",factorial(x));

printf("x to power 3 = %f\n", power(4, 3));
printf("sine(x) = %f\n", doSine(x));

what am i missing? i tried getchar() but i'm not sure that likes long numbers.
  #2  
Old 18-Nov-2003, 01:12
gmn gmn is offline
Junior Member
 
Join Date: Aug 2003
Posts: 33
gmn is on a distinguished road
got it now - its scanf("%lf" isnt it............took suprisingly long to find that using google.
 
 

Recent GIDBlogMeeting the local Iraqis by crystalattice

Thread Tools Search this Thread
Search this Thread:

Advanced Search
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

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
PHP MSN Scripty Thing Andrew MySQL / PHP Forum 19 08-May-2007 11:52
Need C++ help with functions EvilIce C++ Forum 2 01-Dec-2003 16:04
convert long to pointer to char realpopeye C++ Forum 2 26-Sep-2003 10:22
[class] 404 search function code jrobbio MySQL / PHP Forum 6 22-Apr-2003 09:32
[class] Generate Forms Without Using HTML! Elmseeker PHP Code Library 6 11-Mar-2003 12:05

Network Sites: GIDNetwork · GIDWebHosts · GIDSearch · Learning Journal by J de Silva, The

All times are GMT -6. The time now is 15:51.


vBulletin, Copyright © 2000 - 2008, Jelsoft Enterprises Ltd.