|
-
June 5th, 2012, 12:45 PM
#1
Keep getting warning
Hi everybody, glad to join, and will be around for a long time to come hopefully.
I am debugging this code, and I keep getting this warning.
So far I have eliminated every warning that popped up, but this last one I can't seem to figure out how to fix it.
This is the warning
Warning C4244: '=' : conversion from 'float' to 'int', possible loss of data.
Here is my code
Code:
// Preprocessor statements
#include <iostream> //for cin, cout, endl
#include <iomanip> //for setprecision
#include <conio.h> // for _getch()
using namespace std; //for cin, cout, endl
// named constants
const int OZ_PER_POUND = 16; //ounces in one pound
const double POUND_PER_KILO = 2.2; //pounds in one kilogram
int main()
{
float kgs; //variable for converted kilograms
int lbs; //variable for user input pounds
int ounces; //variable for user input ounces
int totalOunces;
cout << "Enter your weight in pounds and ounces: "; //takes user input
cin >> lbs >> ounces; //assigns input pounds to lbs
cout << endl << endl; //and input ounces to ounces
// devide ounces by 16 to get pounds equivalence and add to pounds
// kilograms is total pounds divide by 2.2
kgs = (lbs + ounces / 16) / 2.2f + .11f;
//outputs starting and ending values
cout << fixed << showpoint << setprecision(2) ; //format output to two decimal places
cout << lbs << " pounds and "
<< ounces << " ounces equal to "
<< kgs << " kilograms\n\n";
cout << "Enter kilo: ";
cin >> kgs;
totalOunces = kgs * 2.2f * 16 + .5f; //convert kilo to total ounces
lbs=totalOunces / 16; //integer division total ounces to 16 to get pounds
ounces=totalOunces % 16; //the remainder is ounces
cout << endl << endl
<< kgs << " kilograms equals to "
<< lbs << " pounds and "
<< ounces << " ounces\n\n";
_getch();
return 0;
}
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|