http://www.velocityreviews.com/forums/(E-Mail Removed) wrote:

> Hi everyone, I have this problem and I don't know what's wrong with my

> program. I am trying to enter my two variables height and weight as

> fraction numbers. I declared them as float and also as double, but the

> program aborts when I input a fraction instead of decimal/integer

> number. Could someone tell me where the problem is, and what I need to

> do to correct my code? Thanks a lot in advance, Farah.

>

>

> #include <iostream>

> using namespace std;

>

> int main(void)

> {

> const double INCHES_PER_METER = 39.37;

> const double POUNDS_PER_KG = 2.24;

>

> long double height;

> long double weight;

>

> cout << "METRIC CONVERTER" << endl << endl ;

> cout << "Enter your height in inches " ;

> cin >> height;

>

> cout << "Enter your weight in pounds" ;

> cin >> weight;

> cout << endl ;

>

> double metric_height = height*INCHES_PER_METER;

>

> double metric_weight = weight/POUNDS_PER_KG;

>

>

> cout << "Your height is " << metric_height << " meters." <<

> endl;

> cout << "Your weight is " << metric_weight << " kilograms." <<

> endl;

>

> return 0;

> }
BTW You could check my Quan library for this stuff:

http://quan.sourceforge.net/quan_mat...tml/index.html
Tested on VC7.1, VC8.0 and gcc4

In Quan the code might look like this:

#include <quan/out/length.hpp>

#include <quan/out/mass.hpp>

#include <quan/fixed_quantity/io/input.hpp>

int main(void)

{

std::cout << "METRIC CONVERTER"

<< std::endl << std::endl ;

quan::length::in height;

quan::mass::lb weight;

std::cout << "Enter your height in inches " ;

std::cin >> height.reference_numeric_value<

quan::length::in

>();
std::cout << "Enter your weight in pounds" ;

std::cin >> weight.reference_numeric_value<

quan::mass::lb

>();
std::cout << std::endl ;

quan::length::m metric_height = height;

quan::mass::kg metric_weight = weight;

std::cout << "Your height is "

<< metric_height << std::endl;

std::cout << "Your weight is "

<< metric_weight << std::endl;

}

regards

Andy Little