Work out an area.
What to build
A program that reads two decimals and multiplies them.
Requirements
- Read the width and the height.
- Print
area A.
Input
One line with two numbers.
Output
One line.
Constraints
Each number is from 0 to 1000, with at most one decimal place.
Example
Input:
2.5 4
Output:
area 10
Why it works
double holds fractions, and cout prints as few digits as it needs.
Examples
Example 1 · Input
2.5 4
Expected output
area 10
Example 2 · Input
1.5 1.5
Expected output
area 2.25
Hints
Hint 1
Use double, because the sizes can have fractions.
Hint 2
cin reads doubles too.
Solution
Show one correct solution (try it yourself first)
#include <iostream>
using namespace std;
int main() {
double w, h;
cin >> w >> h;
cout << "area " << w * h << endl;
return 0;
}