C++ double type Read from console
#include <iostream> using namespace std; int main()//from w w w . ja va2 s. c o m { const int SIZE = 6; //size of array double sales[SIZE]; //array of 6 variables cout << "Enter widget sales for 6 days\n"; for(int j=0; j<SIZE; j++) //put figures in array cin >> sales[j]; double total = 0; for(j=0; j<SIZE; j++) //read figures from array total += sales[j]; //to find total double average = total / SIZE; // find average cout << "Average = " << average << endl; return 0; }
#include <iostream> int main() {/*from w ww . ja v a 2s .c om*/ const int inches_per_foot {12}; double shelf_length {}; double shelf_depth {}; double pool_size {}; std::cout << "Enter length (feet): "; std::cin >> shelf_length; std::cout << "Enter depth (feet): "; std::cin >> shelf_depth; std::cout << "Enter length of the side of a pool (inches): "; std::cin >> pool_size; long pools {static_cast<long>((shelf_length * inches_per_foot) / pool_size) * static_cast<long>((shelf_depth * inches_per_foot) / pool_size)}; std::cout << "The number of pools that can be contained in a single layer is " << pools << std::endl; }