Created
August 24, 2011 13:43
-
-
Save torazuka/1168090 to your computer and use it in GitHub Desktop.
Chapter04_7_drill_PPPC++
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #include "../../std_lib_facilities.h" | |
| int main(){ | |
| const string unit_cm = "cm"; | |
| const string unit_m = "m"; | |
| const string unit_in = "in"; | |
| const string unit_ft = "ft"; | |
| const double cm_per_m = 100; | |
| const double cm_per_in = 2.54; | |
| const double in_per_ft = 12; | |
| int count = 0; | |
| double n = 0.0; | |
| string unit = "x"; | |
| double max = 0.0; | |
| double min = 0.0; | |
| cout << "値を単位("<< unit_cm << ", " << unit_m << ", " << unit_in | |
| << ", " << unit_ft << ")つきで入力する。「Ctrl-z」を入力したら終了する。\n"; | |
| while(cin >> n >> unit){ | |
| if(cin.fail()){ | |
| cout << "input error. \n"; | |
| break; | |
| } | |
| double tmp = 0.0; | |
| if(unit == unit_cm){ | |
| tmp = n; | |
| }else if(unit == unit_m){ | |
| tmp = n * cm_per_m; | |
| cout << n << unit_m << " == "; | |
| }else if(unit == unit_in){ | |
| tmp = n * cm_per_in; | |
| cout << n << unit_in << " == "; | |
| }else if(unit == unit_ft){ | |
| tmp = n * in_per_ft * cm_per_in; | |
| cout << n << unit_ft << " == "; | |
| }else{ | |
| } | |
| cout << tmp << unit_cm; | |
| if(tmp < min){ | |
| cout << " the smallest so far"; | |
| min = tmp; | |
| } | |
| if(max < tmp){ | |
| cout << " the largest so far"; | |
| max = tmp; | |
| } | |
| cout << '\n'; | |
| count++; | |
| if(count == 1){ | |
| max = tmp; | |
| min = tmp; | |
| } | |
| } | |
| return 0; | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment