Converting a length in inches to feet-and-inches. - C++ Operator

C++ examples for Operator:Arithmetic Operator

Description

Converting a length in inches to feet-and-inches.

Demo Code

#include <iostream>

int main(){//from   w ww  .  ja  va2  s  . c om
  const int inches_per_foot = 12;

  long length_inches = 0;

  std::cout << "Please enter the number of inches: ";
  std::cin >> length_inches;

  long feet = length_inches / inches_per_foot;
  long inches = length_inches % inches_per_foot;

  std::cout << "In " << length_inches << " inches there are " << feet << " feet and " << inches << " inch(es)." << std::endl;
}

Result


Related Tutorials