help

I need help with this sample problem because a question like this will be on my test, i am so lost, can someone show me how you would even do this.



Arthur, King of the Britons, has tasked you with figuring out the amount of time it would take his
faithful messenger birds to carry messages (which may or may not be in coconuts) across certain
distances. His assistant, Patsy, has provided you with a table that contains the speed of the birds,
and the letter with which the birds will be referred to. Use the table to calculate the times.

Call this file timer.cpp

Bird Speed (m/s) Reference Letter

African Swallow 12.3 S

African Swallow + Coconut 10.97 A

European Swallow 12.8 U

European Swallow + Coconut 10.73 C

Barn Swallow 10.64 B

Barn Swallow + Coconut 9.2 W

1. Print a menu for the user. In the menu, display the birds and their
reference letters. (7

points).
2. Prompt the user the enter the bird in question. Read in the reference
letter. (5 points)

3. Prompt the user to enter the distance (in kilometers) and read in the value (5 points).

4. Use a switch statement on the reference letter to figure out the speed. If the reference letter
is invalid, print an error message. (15 points).

5. Calculate the time taken by the bird and print it, accurate to 4 digits after the decimal point.
(8 points).

6. If the reference letter entered doesn’t match any bird, print an error message (5 points)

7. Add comments wherever appropriate to explain your logic. (5 points)

8. You can assume that the user will only enter the proper type of data, an uppercase character
for the reference letter and a floating point number for the distance
Last edited on
The question has several parts. Which part are you having difficulty with?
Hello DeBary,

Call this file timer.cpp
OK that one is easy.

1. Print a menu for the user. In the menu, display the birds and their
reference letters.

Since this is number one do this first. Post the code you have written for this if you have any questions.

Best to do this first and get it working right and then add to it when you are done.

Hope that helps,

Andy
i was hoping some one could do the sample for me to see how its done, so i can try the other sample problems i was given. Kinda like a guide to use.
Hello DeBary,

As keskiverto once said:
Please note that this is not a homework site. We won't do your homework for you. The purpose of homework is that you learn by doing. However we are always willing to help solve problems you encountered, correct mistakes you made in your code and answer your questions.

We didn't see your attempts to solve this problem yourself and so we cannot correct mistakes you didn't made and answer questions you didn't ask. To get help you should do something yourself and get real problems with something. If your problem is "I don't understand a thing", then you should go back to basics and study again.

Or say that you do not understand the instructions or how to figure them out.

This might help:
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
// <--- Most comon includes.
#include <iostream>
#include <iomanip>
#include <string>
#include <limits>
#include <chrono>
#include <thread>
// Extras.
#include <cctype>
#include <map>

#include "Struct Table.hpp"

// --- Add any header files you create.

// <--- Constant global variables.

// <--- Prototypes.
char MainMenu();
double GetDistance();

int main()
{
	// <--- Define variables
	char choice{};
	double distance{};
	std::map<char, double> birds;
	Bird bird;

	// <--- Your code here.

	choice = MainMenu();
	bird.LoadMap(birds);

	switch (choice)
	{
	case 'A':
		distance = GetDistance();
		break;
	case 'B':
		break;
	case 'C':
		break;
	case 'S':
		break;
	case 'U':
		break;
	case 'W':
		break;
	default:
		break;
	}




	// <--- Keeps console window open when running in debug mode on Visual Studio.
	// The next line may not be needed. If you have to press enter to see the prompt it is not needed.
	//std::cin.ignore(std::numeric_limits<std::streamsize>::max(), '\n');  // <--- Requires header file <limits>.
	std::cout << "\n\n Press Enter to continue";
	std::cin.get();

	return 0;
}

My first thoughts, but still working on it. There is a big difference between what I know and what you know. This makes it hard roe me to figure out what you can do.

Andy
pretty much nothing just started learning about a month ago
Hello DeBary,

I kind of figured that. Let me do some adjusting to come up with something a bit simpler.

For not look at the code I showed you and let me know what you do understand, so I know what I can work with.

Andy
Here's what i have been working on as it was explained to me. Don't know how bad it is.


#include <iostream>
#include <iomanip>

using namespace std;

int main() {

int S=12.3,A=10.97,U=12.8,C=10.73,B=10.64,W=9.2, total;
double x,y;

cout<<"African Swallow = S"<<endl<<"Afrian Swallow + Coconut = A"<<endl<< "European Swallow = U"<<endl<<"European Swallow + Coconut = C"<<endl<<"Barn Swallow = B"<<endl<<"Barn Swallow + Coconut = W"<<endl;




cout<< "Enter Bird:";
cin>> x;
cout<<endl;

cout<<"Enter Distance:";
cin>> y;
cout<<endl;

switch ('x')
{
case 'S': total = x/y;
break;

case 'A':
break;

case 'U':
break;

case 'C':
break;

case 'B':
break;

case 'W':
break;
}



return 0;


1) When posting code, please use code tags to make it readable:

http://www.cplusplus.com/articles/z13hAqkS/

2) You've defined the variables S, A etc to be int, and yet you're trying to assign floating-point values to them. What do you think is going to happen there?

3) You've defined x as a double. However, you're using it to store the thing the user types in in response to the "Enter Bird:" prompt. Presumably, you're actually expecting them to enter a letter there?

4) You're trying to base your switch statement on 'x'. It should be x

'x' is a character value. x is a variable name.


Topic archived. No new replies allowed.