Question: Your task in C is to develop a program that compares two rectangles and prints out which rectangle is smaller. We assume two rectangles in

Your task in C is to develop a program that compares two rectangles and prints out which rectangle is smaller.
We assume two rectangles in a 2D plane. Each rectangle is fully described by its height and width. Widths and heights are decimal numbers greater than zero.
The program is given 4 numbers in the input, these numbers describe widths/heights of the two input rectangles.
The output of the program is the result of the comparison. The program computes the area of the input rectangles and prints out the rectangle with the smaller area, or it answers that the two rectangles have the same area. The exact format of the output is shown below in the example runs.
If the input is invalid (e.g. input values are not decimal numbers, are negative, or inconsistent), the program detects the problem and prints an error message. The format of the error message is again shown below. The following is considered invalid input:
non-numeric value,
invalid width/height (negative, zero, missing).
If the program detects an error, it immediately stops asking for further input data, it prints out the error message and terminates. Thus, the program must validate input data as it reads them. Do not postpone the checks until the entire input is read. The error message shall be printed on the standard output (do not send it to the standard error output).
Please strictly adhere the format of the output. The output must exactly match the output of the reference program. The comparison is done by a machine, the machine requires an exact match. If your program provides output different from the reference, the program is considered malfunctioning. Be very careful, the machine is sensitive event to whitespace characters (spaces, newlines, tabulators). Please note that all output lines are followed by a newline character (
). This applies even to the last line of the output, moreover, this applies even to the error message. Download the enclosed archive. The archive contains a set of testing inputs and the expected outputs. Use the attached files to simplify the testing of your program.
Your program will be tested in a restricted environment. The testing environment limits running time and available memory. The exact time and memory limits are shown in the reference solution testing log. However, neither time nor memory limit could cause a problem in this simple program.
Example program output:
Rectangle #1:
7.512
Rectangle #2:
615
The area is the same.
Rectangle #1:
2218
Rectangle #2:
139
The area of rectangle #2 is smaller.
Rectangle #1:
133e44.25
Rectangle #2:
4e45.28e3
The area of rectangle #1 is smaller.
Rectangle #1:
0.20.1731
Rectangle #2:
0.150.2308
The area is the same.
Rectangle #1:
124
Rectangle #2:
-25
Invalid input.
Rectangle #1:
4 abcd
Invalid input.

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Programming Questions!