Okay i am having problems with this code. for example if i wish to convert 5ft 10.5 inches to meters and cm the programs doesnt give me a value instead it just goes crazy on me....Please help me identify the problem and as well provide me witht the code necessary to fix it.....i would be very apriciative of this.....

 ``123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225`` ``````#include using namespace std; void convert_lengths(); void convert_weights(); int round(double x); //rounds off decimal places void weight_to_metric(); double input_the_lbsandoz(); double convert_the_lbsandoz(); void output_the_kgandg(); //conversion functions for us to metric weight void weight_to_us(); double input_the_kgandg(); double convert_the_kgandg(); void output_the_lbsandoz(); //conversion functions for metric to us weight void length_to_metric(); double input_the_ftandin(); double convert_the_ftandin(); void output_the_mandcm(); //conversion functions for us to metric length void length_to_us(); double input_the_mandcm(); double convert_the_msandcm(); void output_the_ftandin(); //conversion functions for metric to us length int main() { int ans; do { cout << "This program converts lengths and weights." << endl; cout << "Press 1 to convert lengths." << endl; cout << "Press 2 to convert weights." << endl; cout << "Press 0 to end the program." << endl; cout << "Enter: "; cin >> ans; if (ans == 1) { convert_lengths(); } else if (ans == 2) { convert_weights(); } else if (ans == 0) cout << "Program terminated." << endl; else cout << "Please enter a vaild choice." << endl; } while (ans > 2 || ans < 0); return 0; } void convert_lengths() { int answer; do { cout << endl; cout << "You have chosen to convert lengths." << endl; cout << "If you would like to convert ft./in. to m/cm press 1." << endl; cout << "If you would like to convert m/cm to ft./in. press 2." << endl; cout << "If you would like to stop converting lengths press 0." << endl; cout << "Enter: "; cin >> answer; if (answer == 1) length_to_metric(); //conversion function ft/in to m/cm else if (answer == 2) length_to_us(); //conversion function m/cm to ft/in else if (answer == 0) main(); else cout << "Please enter a valid choice." << endl; } while (answer < 0 || answer > 2); } void convert_weights() { int ans; do { cout << endl; cout << "If you would like to convert lbs./oz. to kg/g press 1." << endl; cout << "If you would like to convert kg/g to lbs./oz. press 2." << endl; cout << "If you would like to stop converting weights press 0." << endl; cout << "Enter: "; cin >> ans; if (ans == 1) weight_to_metric(); //weight to metric function else if (ans == 2) weight_to_us(); //weight to us function else if (ans == 0) main(); else cout << "Please enter a valid choice." << endl; } while (ans < 0 || ans > 2); } void length_to_metric() { cout << "You have chosen to convert from us to metric lengths." << endl; output_the_mandcm(); } void length_to_us() { cout << "You have chosen to convert from metric to us." << endl; output_the_ftandin(); } void weight_to_metric() { cout << "You have chosen to convert from us to metric weights." << endl; output_the_kgandg(); } void weight_to_us() { cout << "You have chosen to convert from metric to us." << endl; output_the_lbsandoz(); } double input_the_ftandin() { int feet, inch; double totalin; cout << "Please enter the number of feet: "; cin >> feet; cout << "Please enter the number of inches: "; cin >> inch; totalin = inch + (feet * 12); return totalin; } double convert_the_ftandin() { double totalcm, totalmeters, totalin = input_the_ftandin(); totalcm = totalin * 2.54; totalmeters = totalcm / 100; return totalmeters; } void output_the_mandcm() { double totalmeters = convert_the_ftandin(), totalcm; totalcm = round(totalmeters * 100) % 100; totalmeters = floor(totalmeters); cout << "The total meters are: " << totalmeters << endl; cout << "The total centimeters are: " << totalcm << endl; main(); } double input_the_mandcm() { double meters, cm; cout << "Please enter the number of meters: "; cin >> meters; cout << "Please enter the number of cm: "; cin >> cm; meters = meters + (cm / 100); return meters; } double convert_the_mandcm() { double totalfeet, totalmeters = input_the_mandcm(); totalfeet = totalmeters / .3048; return totalfeet; } void output_the_ftandin() { double totalinches, totalfeet = convert_the_mandcm(); totalinches = totalfeet * 12; totalinches = round(totalinches) % 12; cout << "The total feet are: " << floor(totalfeet) << endl; cout << "The total inches are: " << totalinches << endl; main(); } double input_the_lbsandoz() { double lbs, oz; cout << "Please enter the number of lbs: "; cin >> lbs; cout << "Please enter the number of oz.: "; cin >> oz; lbs = lbs + (oz / 16); return lbs; } double convert_the_lbsandoz() { double totallbs = input_the_lbsandoz(), totalkg, totalgrams; totalkg = totallbs / 2.2046; totalgrams = totalkg * 1000; return totalgrams; } void output_the_kgandg() { double totalkg, totalgrams = convert_the_lbsandoz(); totalkg = floor(totalgrams / 1000); totalgrams = round(totalgrams) % 1000; cout << "The total kilograms are: " << totalkg << endl; cout << "The total grams are: " << totalgrams << endl; main(); } double input_the_kgandg() { double kg, g; cout << "Please enter the number of Kg: "; cin >> kg; cout << " Please enter the number of grams: "; cin >> g; kg = kg + (g / 1000); return kg; } double convert_the_kgandg() { double totallbs, totalkg = input_the_kgandg(); totallbs = 2.2046 * totalkg; return totallbs; } void output_the_lbsandoz() { double totallbs = convert_the_kgandg(), totaloz; totaloz = totallbs * 16; totaloz = round(totaloz) % 16; totallbs = floor(totallbs); cout << "The total pounds are: " << totallbs << endl; cout << "The total ounces are: " << totaloz << endl; main(); } int round(double x) { if(x - floor(x) < 0.5) return floor(x); else return ceil(x); }``````
Actually this program doesn't even compile for me. Maybe you should make sure your compiler is generating all possible warnings. And if you are getting warnings, Fix Them never ignore them.

 main.cpp||In function ‘void convert_lengths()’:| main.cpp|69|error: ISO C++ forbids taking address of function ‘::main’ [-pedantic]| main.cpp||In function ‘void convert_weights()’:| main.cpp|89|error: ISO C++ forbids taking address of function ‘::main’ [-pedantic]| main.cpp||In function ‘void output_the_mandcm()’:| main.cpp|137|error: ‘floor’ was not declared in this scope| main.cpp|140|error: ISO C++ forbids taking address of function ‘::main’ [-pedantic]| main.cpp||In function ‘double convert_the_mandcm()’:| main.cpp|153|warning: no previous declaration for ‘double convert_the_mandcm()’ [-Wmissing-declarations]| main.cpp||In function ‘void output_the_ftandin()’:| main.cpp|163|error: ‘floor’ was not declared in this scope| main.cpp|165|error: ISO C++ forbids taking address of function ‘::main’ [-pedantic]| main.cpp||In function ‘void output_the_kgandg()’:| main.cpp|187|error: ‘floor’ was not declared in this scope| main.cpp|191|error: ISO C++ forbids taking address of function ‘::main’ [-pedantic]| main.cpp||In function ‘void output_the_lbsandoz()’:| main.cpp|214|error: ‘floor’ was not declared in this scope| main.cpp|217|error: ISO C++ forbids taking address of function ‘::main’ [-pedantic]| main.cpp||In function ‘int round(double)’:| main.cpp|221|error: ‘floor’ was not declared in this scope| main.cpp|224|error: ‘ceil’ was not declared in this scope| main.cpp|225|warning: control reaches end of non-void function [-Wreturn-type]|

You can't recursively call main(). This function (main) can't be called by any function including main() in a C++ program.

okay i fixed that.....i re-entered the 5ft and 10.5 inches.....my output is 1 meter and 78cm........but i cant get my program to put out decimal places the value should be around 79.07cm. and i am getting an error i.e. -->

1>c:\comp141\program4c\program4c\program4c.cpp(229): warning C4244: 'return' : conversion from 'double' to 'int', possible loss of data
1>c:\comp141\program4c\program4c\program4c.cpp(231): warning C4244: 'return' : conversion from 'double' to 'int', possible loss of data
and this is refering to this section of code

 ``123456`` ``````int round(double x) { if(x - floor(x) < 0.5) return floor(x); else return ceil(x); }``````
closed account (Dy7SLyTq)
its not an error its a warning so it compiled, but what its saying is that you said at the beginning of the function it will return an int and then you try to return a double. its warning that you might not get the answer you expected
i see.....how can i fix this problem? wat code do i need to add or change?
closed account (Dy7SLyTq)
return (int) yourDoubleVariable; there are better ways but i think that should work
Topic archived. No new replies allowed.