/* program to compute bearings cost, multiple times Sept 22, 1997 CS1711A Class*/ #include int main() { const double PI=3.14159; const double HI_CARBON_PRICE = 1.35; const double LO_CARBON_PRICE = 1.00; int number_bearings; double radius, total_volume, volume_of_one; char carbon,continu; do { // while continu = Y cout << "Input a decimal number for the radius\n"; cin >> radius; cout << "How many bearings?\n"; cin >> number_bearings; cout << "Input carbon: high (h) or low (l)\n"; cin >> carbon; volume_of_one = 4.0/3.0*PI*pow(radius,3.0); total_volume = number_bearings* volume_of_one; if (carbon=='h'|| carbon=='l') /*valid inputs*/ { cout << "The total volume required for " << number_bearings; cout << " bearings of radius " << radius << " is "; cout << total_volume; // format for 2 decimal output cout.setf(ios::fixed); cout.setf(ios::showpoint); cout.precision(2); {if(carbon=='h') cout << endl << "Total cost is $ " << total_volume*HI_CARBON_PRICE; else cout << endl << "Total cost is $ " << total_volume*LO_CARBON_PRICE;}} else /*traps bad input*/ {cout << endl << "Invalid input " << carbon; cout << endl << "Input value must be 'h' or 'l'";} cout << endl; cout << "Input 'Y' to continue, 'N' otherwise"; cin >> continu; } while (continu=='Y'); return 0; }