Bumpkins of Bumpus

The Bumpkins of Bumpus (Borrowed from ACM programming team 2002) project name for this assignment: bumpkin The people of Bumpus (Bumpkins) are a fun, happy, peace-loving people who have a big problem. They have very little depth perception and are constantly running into doors. They've asked you to write a program to let them know when they should duck going through a doorway. Since Bumpkins love fun, some of their doorways have been made intentionally short of force other Bumpkins to either crawl or limbo through the door. Unfortunately, the Bumpkins don't all use the same set of measurements, so some heights are measured in inches, others in feet, others in yards, others in centimeters, and others in meters. To do the conversions, recall that: 1 inch = 2.52 cm 1 yard = 3 ft 1 foot = 12 inches 1 meter = 100 cm Input The input file will begin with a single line, telling you how many Bumpkins want help. Then, for each Bumpkin, there will be data about the Bumpkin and the doorways they reach. The first line of each dataset will give you the Bumpkin's name (all Bumpkins have names of exactly 6 characters), an integer n, the number of doors to process for this Bumpkin (n > 0), and the Bumpkin's height, a floating point number followed by exactly one blank and then one of ‘i', ‘f', ‘y', ‘c', or ‘m' (representing inches, feet, yards, centimeters, and meters). The next n lines will have the height of the doorways in the bumpkin's life, one per line. Each height will be a floating point number followed by exactly one blank and one of ‘i', ‘f', ‘y', ‘c', or ‘m' (representing inches, feet, yards, cm, and meters). Output For each bumpkin, print the name of the Bumpkin on one line and then for each door, print the way the Bumpkin should travel through the door. Decide on a mode of travel based on the table below, where b is the height of the Bumpkin, d is the height of the door (expressed in the same units): Door Height Travel Method d > b * 1.25 Stilts b * 1.25 >= d > b *1.05 Walk b * 1.05 >= d > b * 0.65 Duck b * 0.65 >= d > b * 0.40 Crawl b * 0.40 >= d > b * 0.25 Limbo b * 0.25 >= d Blocked Have one blank line after each data set. Sample The following are sample inputs and outputs. Note that the input is from the keyboard and use appropriate prompting. You will need to look above to recall what the input values represent. (For 10pts extra credit use an input file called bumpkin.in that would contain all of the lines of input). Sample Input 2 Mookin 3 150.4 c 75 i 2 f 151 c Kimkin 1 67.3 i 204.5 c Output corresponding to the Sample Input Mookin Doorway 1: Stilts Doorway 2: Crawl Doorway 3: Duck Kimkin Doorway 1: Walk This is in C++ I am confused about this.
I only need advice on where do I begin with this. I would like to try to figure this out myself, but am having a hard time. I am a beginner at c++, but this was assigned by my instructor.
This is 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
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69

#include <iostream>
#include <string>

using namespace std;

int main()
{
int number, n;
string name;
char unit;
float b, d;

// Prompts user input for number of Bumpkins.
cout << "Enter number of Bumpkins: ";
cin >> number;
cout << endl;

// Loop to get information for each Bumpkin.
for (int count = 1; count <= number; count++)
{
cout << "Enter name of Bumpkin, number of doors, height of the Bumpkin, and the units of the height (space in between): ";
cin >> name >> n >> b >> unit;
}
// Loop to get the height of each door.               
 for (int i = 1; i <= n; i++)
 {
	 cout << "Enter height with unit of measurement of door " << i << ": \n";
   cin >> d >> unit;
 
    if (d > b * 1.25)
	{
	
       cout << "Stilts\n";
	}
	
    else if (b * 1.25 >= d > b *1.05)
	
        cout << "Walk\n";
	
    else if  (b * 1.05 >= d > b * 0.65)
	
      
	  cout << " Duck\n";
	
    else if (b * 0.65 >= d > b * 0.40)
	
       cout << "Crawl\n";
	
	
    else if (b * 0.40 >= d > b * 0.25)
	
      cout << "Limbo\n";
	
    else if (b * 0.25 >= d)
	
      cout << "Blocked\n";

	else 
		cout << "invalid entry\n";
	
 


 
system ("pause");
return 0;
 }


I am getting unsafe use of type boolean in my else if statements
else if (b * 0.40 >= d > b * 0.25)

You can't abbreviate your logical connections like that in c++:

else if (b * 0.40 >= d && d > b * 0.25)

BTW, that's a hell of an assignment for a beginner!
Last edited on
I know right.

This is what I have now with corrections, but it is not looping right.

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
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71

#include <iostream>
#include <string>

using namespace std;

int main()
{
int number, n;
string name;
char unit;
float b, d;

// Prompts user input for number of Bumpkins.
cout << "Enter number of Bumpkins: ";
cin >> number;
cout << endl;

// Loop to get information for each Bumpkin.
for (int count = 1; count <= number; count++)

cout << "Enter name of Bumpkin, number of doors, height of the Bumpkin, and the units of the height (space in between): ";
cin >> name >> n >> b >> unit;
cout << name;
// Loop to get the height of each door.               
 for (int i = 1; i <= n; i++)
 {
	 cout << "Enter height with unit of measurement of door " << i << ": \n";
     cin >> d >> unit;
     
 
 
    if (d > b * 1.25)
	
	
       cout <<"Doorway :"<< i << "Stilts\n";
	
	
    else if (b * 1.25 >= d && d > b *1.05)
	
        cout <<"Doorway :" << i << "Walk\n";
	
    else if  (b * 1.05 >= d && d > b * 0.65)
	
      
	  cout << "Doorway :"<< i << " Duck\n";
	
    else if (b * 0.65 >= d && d > b * 0.40)
	
       cout << "Doorway :"<< i << "Crawl\n";
	
	
    else if (b * 0.40 >= d && d > b * 0.25)
	
      cout <<"Doorway :"<< i << "Limbo\n";
	
    else if (b * 0.25 >= d)
	
      cout << "Doorway :"<< i << "Blocked\n";

	else 
		cout << "invalid entry\n";
 }
 


 
system ("pause");
return 0;
 }
Topic archived. No new replies allowed.