C++ cin Prompt user to enter an integer to control the program's output.

Description

C++ cin Prompt user to enter an integer to control the program's output.

#include <iostream>
#include <iomanip>

int main()/* www  .  j  a v  a  2  s  .  co m*/
{
  const float pi = 3.14159f;

  float radius {};
  float areaOfCircle {};
  unsigned int sigFigs {};

  std::cout << "Please enter the radius: ";
  std::cin >> radius;

  std::cout << "Please enter the desired precision of the output (significant figures): ";
  std::cin >> sigFigs;

  areaOfCircle = pi * radius * radius;

  std::cout << "The area of the circle is approximately equal to "
            << std::setprecision(sigFigs)
            << areaOfCircle << " square units." << std::endl;
}



PreviousNext

Related