help me pls, I am not quite sure if I am doing right or not.

Write a program in C++ that prompts the user to enter a number representing inches and breaks it down into inches, feet and yards. For example, if a user enters 70 inches, your program should print: 70 in = 1 yd 2 ft 10 in. Here is how you convert:
1 yard = 3 feet
1 foot = 12 inches
If you divide 70 inches by 12 you get the number of feet as a quotient and the remaining number of inches as a remainder:
70 (in) / 12 = 5 (ft) and 70 (in) % 12 = 10 (in).
So, 70 in = 5 ft 10 in. Now, because 5 feet is more than 1 yard (3 feet), you have to divide 5 by 3 to get the number of yards:
5 (ft) / 3 = 1(yd) and 5 (ft) % 3 = 2 (ft)
At the end you should print: 70 in = 1 yard 2 ft 10 in.

Here is my code about the question above.

#include <iostream>
#include <cmath>


using namespace std;

int main()
{
int yard, feet, inches, input;

cout <<"Enter any values of inches: ";
cin >> input;

feet = input / 12;
inches = input % 12;
yard = feet/3;

if (feet >= 3)
{
feet = feet % 3;
cout << yard << "yard" << feet << "ft" <<inches << "in" ;
}




return 0;
}

Last edited on
Topic archived. No new replies allowed.