View Single Post
Old 02-05-2007, 02:55 PM   #2 (permalink)
redhead
Newbie
 
redhead's Avatar
 
Join Date: Jun 2002
Location: Denmark
Posts: 1,720
redhead is on a distinguished road
It's pretty simple, if you take a look at the answer I provided last, use the same form to begin the program ie:
Code:
#include <iostream>

int main()
{
  const float pi = 3.141593;
Since we need to use some arrithmetic which involves dicimal numbers, we need to declare them as floats.

The math in this, is a well known formular, which we all probably learned in 4.th grade or there about.. Where you can calculate the circumference if you know the diameter, and you have PI handy.

Since we need to make a nice display of the result, it would be wise to use som I/O manipulation provided from iomaip.h like forinstance precision().

Combining this we end up with something like this:
Code:
#include <iostream>
#include <iomanip>
using namespace std;

int main()
{
  const float pi = 3.141593;
  float diameter=-1, price=0;
  while(diameter < 0){
    cout << "Please enter the diameter of the circle: ";
    cout.flush();
    cin >> diameter;
    if(diameter < 0)
      cout << "Sorry it's impossible to have a negative diameter" << std::endl;
  }
  cout << "Please enter the price of the railing material: ";
  cout.flush();
  cin >> price;
  cout << fixed << showpoint << setprecision(2);
  cout << "The circumference is: " << /* here you continue... */
__________________
Don't worry Ma'am, We're university students, We know what We're doing.
-----
If you pull the pin, Mr.Grenade would no longer be your friend.
-----
01000111 01101111 00100000 01000011 00100000 00100001
redhead is offline   Reply With Quote