Nice, now I got it to work and I moved on to the next exercise.
Add a unit to each double entered; that is, enter values such as 10cm, 2.5in, 5ft or 3.33m. Accept four units:
cm, m, in, ft. Assume conversion factors 1m == 100cm, 1in == 2.54cm, 1ft == 12in. Read the unit indicator
into a string . You may consider 12m (with a space between the number and the unit) equilavent to 12m
(without the space). Reject values withot units or with illegal representations of units, such as y, yard,meter,
km and gallons.
Here is the code I have so far:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72
|
#include <iostream>
#include <cmath>
#include <cstdio>
int main()
{
double a=0.0;
double b=0.0;
double smaller=1/0.0;
double larger=-1/0.0;
double input=0.0;
string unit;
string smallest_unit;
string largest_unit;
bool unit;
bool unit= true;
if (unit== cm or m or in or ft)
else
bool unit = !true;
std::cout<< "Enter a floating point value followed by a unit(cm,m,in,ft)";
while(std::cin>>input>>string unit) {
if (unit=="m") //convert meters to centimeters
a=b*100;
else if (strcmp(...) == 0) //convert inches to centimiters
a=b*2.54;
else if (strcmp(...) == 0) //convert feet to centimeters
a=b*30.48;
else if (strcmp(...) == 0)
a=b;
if(input>larger) {
larger = input;
std::cout << input << unit" is the largest so far" << std::endl;
}
else if(input<smaller) {
std::cout << input << unit" is the smallest so far" << std::endl;
}
else if(input < larger and input > smaller) {
std::cout << input unit << std::endl;
}
}
}
|