Prompt user to enter an integer to control the program's output. - C++ Language Basics

C++ examples for Language Basics:Console

Description

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

Demo Code

#include <iostream>
#include <iomanip>

int main()//from   www.j a va  2 s.c o  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;
}

Result


Related Tutorials