need assitance with my C++

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;


}

Last edited on
Can you please post this with code tags reading it is giving me a headache.

Also I am not sure what your trying to do as a simple solution would be to use a function that receives two values and then a series of if statements or switch statements to get the type of paper.

1
2
3
4
5
6
7
8
void paperType(int width, int length){
    if(width == some value && length == some value){
         cout << "Paper type is: " << endl;
    }
    else if(width.....){
    }
    else
}
hi kenshin, thanks for the reply. I edited and put codetags in.

basically the quesiton needs the display to show Use A1, Use A2... or A3, or A4, or Not in Stock.

the sizes are:

A1 (594mm x 840mm)
A2 (420mm x 594mm)
A3 (297mm x 420mm)
A4 (210mm x 297mm)

but my problem is, how do I make it so it still accepts my width/length input if its the other way around.

ie (width 200 x length 600) and (witdh 600 x length 200)
Asuming you always want your length to be a larger size than your width, simply check after you input the values, and adjust accordingly.

1
2
3
4
5
if (width > length) {
  int temp = width;
  width = length;
  length = temp;
}


This just swaps them into the proper order before you do your testing on their values.

~psault
Last edited on
Topic archived. No new replies allowed.