quotient = numerator / denominator; remainder = numerator % denominator;
| 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; std::cout << ", the root of the sum of their squares 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 ...
}
|
Welcome to HowManyFit! We estimate how many (small) marbles, ping pong balls, and tennis balls fit in a container whose size you specify. Please enter a name for the container (as a single word): carton Please enter the size of a(n) carton in litres (e.g. 4.6): 1.5 A carton of size 1.5 litres holds 105.3 to 128.7 small marbles 27.7 to 33.8 ping pong balls 5.0 to 6.1 tennis balls Thanks for using HowManyFit! |