Decimal Problem In C

Reply

Join Date: Aug 2004
Posts: 140
Reputation: Mahen is an unknown quantity at this point 
Solved Threads: 2
Mahen Mahen is offline Offline
Junior Poster

Decimal Problem In C

 
0
  #1
Aug 8th, 2004
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:
Reply With Quote Quick reply to this message  
Join Date: Jun 2004
Posts: 609
Reputation: freesoft_2000 is an unknown quantity at this point 
Solved Threads: 7
freesoft_2000 freesoft_2000 is offline Offline
Practically a Master Poster

Re: Decimal Problem In C

 
0
  #2
Aug 8th, 2004
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
Reply With Quote Quick reply to this message  
Join Date: Jun 2004
Posts: 34
Reputation: Fili is an unknown quantity at this point 
Solved Threads: 0
Fili's Avatar
Fili Fili is offline Offline
Light Poster

Re: Decimal Problem In C

 
0
  #3
Aug 8th, 2004
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
Reply With Quote Quick reply to this message  
Join Date: Aug 2004
Posts: 140
Reputation: Mahen is an unknown quantity at this point 
Solved Threads: 2
Mahen Mahen is offline Offline
Junior Poster

Re: Decimal Problem In C

 
0
  #4
Aug 8th, 2004
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.
Reply With Quote Quick reply to this message  
Join Date: Apr 2004
Posts: 4,343
Reputation: Dave Sinkula has a brilliant future Dave Sinkula has a brilliant future Dave Sinkula has a brilliant future Dave Sinkula has a brilliant future Dave Sinkula has a brilliant future Dave Sinkula has a brilliant future Dave Sinkula has a brilliant future Dave Sinkula has a brilliant future Dave Sinkula has a brilliant future Dave Sinkula has a brilliant future Dave Sinkula has a brilliant future 
Solved Threads: 237
Team Colleague
Dave Sinkula's Avatar
Dave Sinkula Dave Sinkula is offline Offline
long time no c

Re: Decimal Problem In C

 
0
  #5
Aug 8th, 2004
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
  */
"One of the methods used by statists to destroy capitalism consists in establishing controls that tie a given industry hand and foot, making it unable to solve its problems, then declaring that freedom has failed and stronger controls are necessary." --Ayn Rand
Reply With Quote Quick reply to this message  
Reply

This thread is more than three months old.
Perhaps start a new thread instead?
Message:


Thread Tools Search this Thread



About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC