•
•
•
•
What is DaniWeb IT Discussion Community?
You're currently browsing the C++ section within the Software Development category of DaniWeb, a massive community of 456,555 software developers, web developers, Internet marketers, and tech gurus who are all enthusiastic about making contacts, networking, and learning from each other. In fact, there are 3,483 IT professionals currently interacting right now! Registration is free, only takes a minute and lets you enjoy all of the interactive features of the site.
Please support our C++ advertiser: Programming Forums
Views: 644 | Replies: 3
![]() |
•
•
Join Date: Oct 2007
Posts: 3
Reputation:
Rep Power: 0
Solved Threads: 0
hey guys im tryin to do a conversion program im trying to convert pounds to kilograms i input 10 pounds and 4 ounces and it gives me a total of 4.65 kilograms but i want to split that up so it says kilograms and grams so it would be like 4.00 kgms and 649.33 gms what i wanna know is how do you output the .65 kilograms
#include <iostream>
#include <cmath>
using namespace std;
int main()
{
cout << "Please enter number of pounds: ";
cin >> pounds;
cout << "Please enter number of ounces: ";
cin >> ounces;
tpds = ounces / 16;
tkgms = (tpds + pounds) / 2.2046;
toun = (tpds + pounds) % 2.2046;
cout << "Kilograms: " << tkgms << endl;
cout << "For " << pounds << " pounds and ";
cout << ounces << " ounces:" << endl;
cout << "Conversion is: " << floor(tkgms) << " kilograms and ";
cout << toun << " grams.\n"; Last edited by gee1288 : Oct 19th, 2007 at 1:00 pm.
•
•
Join Date: Aug 2007
Location: South Dakota
Posts: 993
Reputation:
Rep Power: 6
Solved Threads: 97
>what i wanna know is how do you output the .65 kilograms
If you assign the value to an int, the fractional part is truncated. Subtract that from the original value and you get just the fractional part:
If you assign the value to an int, the fractional part is truncated. Subtract that from the original value and you get just the fractional part:
cplusplus Syntax (Toggle Plain Text)
#include <iostream> double integral_part ( double value ) { return int ( value ); } double fractional_part ( double value ) { return value - integral_part ( value ); } int main() { double d; std::cout<<"Enter a floating-point value: "; if ( std::cin>> d ) { std::cout<<"Integer half: " << integral_part ( d ) <<'\n'; std::cout<<"Fractional half: " << fractional_part ( d ) <<'\n'; } }
![]() |
•
•
•
•
•
•
•
•
DaniWeb C++ Marketplace
•
•
•
•
Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
Similar Threads
- Conversion (VB.NET)
- Google's AdWords Conversion Tracking System (Pay-Per-Click Advertising)
- Are You Using These Keyword Selection Guidelines to Improve Website Conversion Rates? (Search Engine Optimization)
- Need help with this conversion program (C++)
- code conversion from c\c++ to java (C++)
- Java to C# Conversion (C#)
- project conversion (C++)
- Tower to Rack conversion Kit (Networking Hardware Configuration)
- Pounds to Grams Conversion (C++)
Other Threads in the C++ Forum
- Previous Thread: need help ..
- Next Thread: C++ calculations



Linear Mode