943,502 Members | Top Members by Rank

Ad:
  • C Discussion Thread
  • Unsolved
  • Views: 3436
  • C RSS
Aug 8th, 2004
0

Decimal Problem In C

Expand Post »
Hi everyone,
Some questions in my previous post is still left unanswered.
Here it is again:

How can i accept decimal numbers from STDIN and perform arithmetic operations on it in C.

How can i create a subroutine within a program, that can be called again & again at different part of a program.
THANKS :mrgreen:
Similar Threads
Reputation Points: 10
Solved Threads: 2
Junior Poster
Mahen is offline Offline
144 posts
since Aug 2004
Aug 8th, 2004
0

Re: Decimal Problem In C

Hi everyone,
I not very clear what you are talking about.

Receving decimal numbers???

Do you mean returning decimal numbers from a function

declare a variable as float
float a;
a = rew( ); // Is this what you mean

As for your other question

You cannot call a function within its own function.
You can declare the function externally being public or private
and call it
if there is arguments and a return value
a = gow(c,d); // Is this what you mean

if it has no arguments or any return values

gow(); //Is this what you mean

I really hope this helps you

Yours Sincerely

Richard West
Reputation Points: 25
Solved Threads: 10
Practically a Master Poster
freesoft_2000 is offline Offline
623 posts
since Jun 2004
Aug 8th, 2004
0

Re: Decimal Problem In C

For reading you use scanf() with format specifier "%f","%g","%e" or printf();
the variable tyoe is float and functions are in math.h

You need functions->read tutorials
Reputation Points: 16
Solved Threads: 0
Light Poster
Fili is offline Offline
34 posts
since Jun 2004
Aug 8th, 2004
0

Re: Decimal Problem In C

OK, let me clear things up, suppose i want to enter 23.45 using SCANF, the program will only accept the 23 and use the .45 for the other SCANF, how can i avoid it.
Reputation Points: 10
Solved Threads: 2
Junior Poster
Mahen is offline Offline
144 posts
since Aug 2004
Aug 8th, 2004
0

Re: Decimal Problem In C

First, avoid scanf. Second, use a floating point type to enter a floating point value.
#include <stdio.h>
  
  int main()
  {
     double number;
     fputs("Enter number: ", stdout);
     fflush(stdout);
     if ( scanf("%lf", &number) == 1)
     {
  	  printf("number = %g\n", number);
     }
     return 0;
  }
  
  /* my output
  Enter number: 23.45
  number = 23.45
  */
Team Colleague
Reputation Points: 2780
Solved Threads: 312
long time no c
Dave Sinkula is offline Offline
4,790 posts
since Apr 2004

This thread is more than three months old

No one has posted to this discussion for at least three months. Please let old threads die and do not reply to them unless you feel you have something new and valuable to contribute that absolutely must be added to make the discussion complete. Otherwise, please start a new thread in this forum instead.
Message:
Previous Thread in C Forum Timeline: Array in talbe (problem)
Next Thread in C Forum Timeline: Network Applications





About Us | Contact Us | Advertise | Acceptable Use Policy
Forum Index | Build Custom RSS Feed


Follow us on Twitter


© 2011 DaniWeb® LLC