This is what I have so far and I can't figure out how to get the converted length in my output file so that 312 inches converts to 3 yards, 1 foot, and 3 inches.

#include <iostream.h>
#include <fstream.h>


using namespace std;


int main()
{
ofstream outfile;


int centimeters;
int inches;
int yards;
int feet;


outfile.open("lengthout.txt");


cout << "Enter length in centimeters: ";
cin >> centimeters;
cout << endl;
cout << "The number entered was " << centimeters
<< " for centimeters. " << endl;
inches = centimeters * 0.3937;



outfile << "Program #3 Output by " << endl;
outfile << "Input Length in centimeters: " << centimeters << endl;
outfile << "Length in inches: " << inches << endl;
outfile << "Converted length: "


return 0;
}

Recommended Answers

All 2 Replies

You shouldn't use integers for math if you are multiplying numbers with decimals. Use floats or doubles...

im not sure, but you may want to try using the modulus operator "%".
for example... to turn feet into yards and feet you could enter

int yards, feet;
yards = feet / 3;
feet = feet % 3;
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.