Hi all, i'm new at C++, and just doing a beginners course on it at college.
I've got this assignment for this week, and got stuck...
The question is:
There are 4 different sizes
of paper in stock that are denoted by A1, A2, A3, and A4. Your task is to write a C++
program that automatically determines the size to be used depending on the dimensions
of the work that needs to be done.
The sizes of the paper sheets in stock are:
A1 (594mm x 840mm)
A2 (420mm x 594mm)
A3 (297mm x 420mm)
A4 (210mm x 297mm)
Make sure that it behaves as shown in these sample
runs:
Enter the dimensions of the poster in mm: 115 250
Use A4
basically, I've done most of it, then I realised, crap... I have to also consider if its the other way around as well, as in... instead of length x width, its width x length. Would appreciate if someone could help me/teach me what I need to add to make it work. So far heres what I have...
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51
|
// poster.cpp
#include <iostream>
using namespace std;
int main ()
{
int length, width;
cout << "Enter the dimensions of the poster in mm: ";
cin >> length >> width;
if (length <= 210)
if (width <= 297)
{
cout << "Use A4" << endl;
}
if (length <= 297)
if (length > 210)
if (width <= 420)
if (width > 297)
{
cout << "Use A3" << endl;
}
if (length <= 420)
if (length > 297)
if (width <= 594)
if (width > 420)
{
cout << "Use A2" << endl;
}
if (length <= 594)
if (length > 420)
if (width <= 840)
if (width > 594)
{
cout << "Use A1" << endl;
}
if (length > 594 || width > 840)
{
cout << "Not in Stock" << endl;
}
return 0;
}
|