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... */