The project description is as follows:
The task is to develop a program to compute how to produce a sail using standardized sheets of fabric.
We assume there is a fabric produced in rectangular sheets, the size of the sheet is known (width and height). Next, there is a request to produce a rectangular sail (again, width and height is given). The program reads the dimensions and computes the number of fabric sheets needed to produce the sail.
The computation is slightly more complicated, we assume there is an overlap needed in the places where the sheets are sewed. Thus the program reads the size of the fabric, the size of the sail and compares them. If the fabric sheets must be sewed, the program further asks for the width of the required overlap.
We assume the fabric sheets are sewed in a rectangular grid, i.e. all the rectangles are aligned in the same orientation. Moreover, we assume that the extra material (that exceeds the size of the sail) must be discarded (cannot be re-used).
The input of the program consists of:
- the dimensions of the fabric sheet,
- the dimensions of the sail, and
- the width of the overlap (only if the fabric must be actually sewed).
The output of the program is the minimal number of the fabric sheets needed to produce the sail. Some combinations of dimensions may cause the sail cannot be produced, an extra output is displayed in such a case (see below).
The program must validate input data. If the input is invalid, the program must detect it, it shall output an error message (see below) and terminate. If displayed, the error message must be displayed to the standard output (do not send it to the error output) and the error message must be terminated by a newline (\n). The input is considered invalid, if:
- the width, height, or overlap size is not a decimal number,
- width or height is missing, is negative or zero,
- overlap size is negative (i.e. overlap size may be zero),
- overlap size is missing and the overlap size is needed for the computation.
The sample program runs as follows:
Sheet dimensions:
2.5 3
Sail dimensions:
12 5
Overlap:
0
Sheets: 8
Sheet dimensions:
2.5 3
Sail dimensions:
12 5
Overlap:
0.2
Sheets: 12
Sheet dimensions:
4 3
Sail dimensions:
5 4
Overlap:
0.1
Sheets: 2
Sheet dimensions:
3 4
Sail dimensions:
2 2
Sheets: 1
Sheet dimensions:
1e100 1e100
Sail dimensions:
3e100 3e100
Overlap:
1e99
Sheets: 16
Sheet dimensions:
0.71 1
Sail dimensions:
4.91 1.7
Overlap:
0.01
Sheets: 14
Sheet dimensions:
2 2
Sail dimensions:
5 1
Overlap:
1.5
Sheets: 7
Sheet dimensions:
2 1
Sail dimensions:
5 1
Overlap:
1.5
Sheets: 7
Sheet dimensions:
1 1
Sail dimensions:
5 1
Overlap:
1.5
No solution.
Sheet dimensions:
3 abcd
Invalid input.
Sheet dimensions:
-5 1
Invalid input.
I have already worked on it a bit but I can't figure out how to do the overlap calculation and how to add it to my code. I also still can't figure out how to print Invalid input if the input is a negative number or it is not a number.
I have attached my .c file here too.
sails.c
Code:
#include <stdio.h>
int main() {
float sheetdimh, sheetdimw, sheetarea, saildimh, saildimw, sailarea, overlap, sheets;
printf("Sheet dimensions:\n");
scanf("%g%g", &sheetdimh,&sheetdimw);
printf("Sail dimensions:\n");
scanf("%g%g", &saildimh,&saildimw);
printf("Overlap:\n");
scanf("%g", &overlap);
sheetarea = sheetdimh * sheetdimw;
sailarea = saildimh * saildimw;
sheets = sailarea / sheetarea;
printf("Sheets: %g\n", sheets);
return 0;
}