0

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;
}

Edited by happygeek: fixed formatting

3
Contributors
2
Replies
3
Views
12 Years
Discussion Span
Last Post by blackdove
0

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

0

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;
This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.