|
From: Robert D B. <lon...@ju...> - 2001-03-06 16:33:26
|
wear_cost = ((km_travelled / 1000) - (((int)km_travelled % 1000) / 100)
* 200);
This needs to be cast as an int
Regards lonestar36
On Wed, 7 Mar 2001 01:13:31 +1100 "petermead" <pet...@im...>
writes:
> Robert I like it...
>
> &
>
> Q: Any ideas on why this modulus returns an error when compiled?
>
> /* basic code I am learning for colledge.
> Hire cost is $0.30 per km and $200 per complete 1000km travelled */
> // To Calculate hire car cost.
> // By Peter Mead 06-03-2001.
>
> #include <iostream.h>
>
> void main()
>
> {
>
> float ini_reading;
> float fin_reading;
> float km_travelled;
> float trav_cost;
> float wear_cost;
>
> // Title.
> cout << "Calculate the hire car cost. \n\n";
>
> // Ask for initial odometer reading.
> cout << "Please Enter the initial odometer reading :";
> cin >> ini_reading;
>
> // Ask for finial reading.
> cout << endl;
> cout << "Please Enter the finial odometer reading :";
> cin >> fin_reading;
>
> // Calculate costs.
> km_travelled = (fin_reading - ini_reading);
> trav_cost = (km_travelled * 0.3);
> wear_cost = ((km_travelled / 1000) - ((km_travelled % 1000) /
> 100) *
> 200);
>
> // Display total hire car cost.
> cout << "The total hire car cost is $" << (wear_cost +
> trav_cost);
> cout << endl << endl;
>
> // Finish program.
> cin.ignore(1);
> cin.get();
>
>
> }
>
> TIA...
>
> ----==<(*)>==----
> Peter Mead :^)
> pet...@im...
> (GMT+10)_Victoria, Australia
> ~~~~~~~~~~~~~~~~~~~~~~
> ----- Original Message -----
> From: <Rob...@ao...>
> To: <dev...@li...>
> Sent: Wednesday, March 07, 2001 12:22 AM
> Subject: Re: [Dev-C++] float and double
>
>
> In a message dated 06/03/01 13:09:20 GMT Standard Time,
> pet...@im... writes:
>
> << Any quick explanations on the difference between a float and a
> double
> when
> used as variables? >>
>
> Take a look at float.h :-)
>
> Or look below ;o)
>
> <</*
> * The characteristics of float.
> */
>
> /* The radix for floating point representation. */
> #define FLT_RADIX 2
>
> /* Decimal digits of precision. */
> #define FLT_DIG 6
>
> /* Smallest number such that 1+x != 1 */
> #define FLT_EPSILON 1.19209290e-07F
>
> /* The number of base FLT_RADIX digits in the mantissa. */
> #define FLT_MANT_DIG 24
>
> /* The maximum floating point number. */
> #define FLT_MAX 3.40282347e+38F
>
> /* Maximum n such that FLT_RADIX^n - 1 is representable. */
> #define FLT_MAX_EXP 128
>
> /* Maximum n such that 10^n is representable. */
> #define FLT_MAX_10_EXP 38
>
> /* Minimum normalized floating-point number. */
> #define FLT_MIN 1.17549435e-38F
>
> /* Minimum n such that FLT_RADIX^n is a normalized number. */
> #define FLT_MIN_EXP (-125)
>
> /* Minimum n such that 10^n is a normalized number. */
> #define FLT_MIN_10_EXP (-37)
>
>
> /*
> * The characteristics of double.
> */
> #define DBL_DIG 15
> #define DBL_EPSILON 1.1102230246251568e-16
> #define DBL_MANT_DIG 53
> #define DBL_MAX 1.7976931348623157e+308
> #define DBL_MAX_EXP 1024
> #define DBL_MAX_10_EXP 308
> #define DBL_MIN 2.2250738585072014e-308
> #define DBL_MIN_EXP (-1021)
> #define DBL_MIN_10_EXP (-307)>>
>
> XANDER: Who's a little fear demon? Come on, who's a little fear
> demon?
> GILES: Don't taunt the fear demon.
> XANDER: Why? Can he hurt me?
> GILES: No, it's just tacky.
> ...
> GACHNAR: I am the Dark Lord! Fear me!
> WILLOW: Heâs so cute!
> BtVS Season 4 - "Fear, Itself"
>
> _______________________________________________
> Dev-cpp-users mailing list
> Dev...@li...
> http://lists.sourceforge.net/lists/listinfo/dev-cpp-users
>
>
> _______________________________________________
> Dev-cpp-users mailing list
> Dev...@li...
> http://lists.sourceforge.net/lists/listinfo/dev-cpp-users
> |