P: n/a | <fa**********@gmail.comwrote in message news:11**********************@i42g2000cwa.googlegr oups.com.. 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; } Fractions, such as 1/2 2/3 etc. are not stored in doubles or floats or ints. They are actually formulas. The values you can store are 0.5 and 0.6666 however. If you want to be able to put in fractions, such as 12 1/2 then you will need to parse the string and do the math yourself. If I wanted to do this I would look for a space in the string. If I found a space I would take everything before the space as the whole number. Then I'd look for the /. I would take everthing from the space to the / as the operator. Everything after the / as the devisior. Then simply: double Height = Whole + operator / devisor; |
|
- Aug 04, 2011 simple input and output c program.
- Open source 2D graph plotting library for the MingW C or C compiler koolplot. Basic 2D Graph Plotting: koolplot is freeware open-source. It is a very simple-to-use software library for drawing 2-dimensional graphs from C or C programs. Sample koolplot output.
- Sep 16, 2016 Decimal Number Variables As described above, an integer variable has no fractional part. Integer variables tend to be used for counting, whereas real numbers are used in arithmetic. C uses one of two keywords to declare a variable that is to be as.
Print Fraction In Dev C Template
Aug 31, 2010 Displaying fractions as 1/8 rather than. Iposible auto tune 7 en protools 11 mac. Displaying fractions as 1/8 rather than.125? I have made a program that displays a grid size for tile installations. My friend is familiar with fractions, but I know he will be confused when he sees (for example) 20.125, which is 20 and 1/8. I'm new to C so I may not be the best at.
Bed room producer auto tune. Comping is so mind-numbingly boring that even Gottwald, with his powers of concentration, can’t tolerate it.