user inputs | expected output | ||
numerator | denominator | quotient | remainder |
17 | 5 | 3 | 2 |
11 | 13 | 0 | 11 |
12 | 4 | 3 | 0 |
std::cout << std::setw(ColWidth) << numerator << std::endl; std::cout << std::setw(ColWidth) << denominator << std::endl; std::cout << std::setw(ColWidth) << userInitial << std::endl; std::cout << std::setw(ColWidth) << "And this!" << std::endl;
std::cout << std::setiosflags(std::ios::fixed); std::cout << std::setprecision(5);
double third = 1/3.0;
std::cout << Pi << std::endl; std::cout << third << std::endl;
double xVal, yVal; // two values to be supplied by the user double answer; // location where we'll store the result of our call std::cout << "Enter two numeric values:" << std::endl; std::cin >> xVal >> yVal; answer = rootOfSumSquares(xVal, yVal); std::cout << "For inputs " << xVal << " and " << yVal << ", the result is "; std::cout << answer << std::endl;
double rootOfSumSquares(double x, double y) { double sumSqs; // will hold the sum of the two squares double root; // will hold the root of the sum of the squares (our final answer) sumSqs = x*x + y*y; root = sqrt(sumSqs); return root; }
// sample structure for a program with its own functions foo and blah #includes and constants // prototypes int foo(double a, int b, float c); double blah(int m) // main routine int main() { ... main's code ... } // full versions int foo(double a, int b, float c); { ... foo's code ... } double blah(int m) { ... blah's code ... } |