Types

I have no idea how to go about this. I do not know how to assign the type 1, 2 and 3 to a specific type of horse. I know that I can put lightRiding = 1, largeRiding = 2, draft = 3. However, when I get to the part where I input the type of horse I have, I do not know how to attach type to the horse and number, or how to cout whichever type of horse I selected in it being the type of horse rather than number. Any help? Thanks!


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
#include <iostream>
#include <iomanip>
using namespace std;

int main()

{
	int lightRiding, largeRiding, Draft;
			
	        type = lightRiding = 1
		type = lightriding = 2
		type = draft = 3;

	cout << setw(50) << "Noahs Horse Yard\n";
	cout << "_______________________________________________________________________________\n";

	cout << "Horse type";
	cout << setw (40) << " Minimum Optimum weight";
	cout << setw (30) << "Maximum Optimum Weight\n";
	
										
				// key
	cout << "_______________________________________________________________________________\n";
	cout << "\n";
	cout << "1." << " Light Riding Horse" << setw(20)  << "840"   << setw(25) << "1200\n";
	cout << "\n";
	cout << "2." << " Large Riding Horse" << setw(20)   << "1110" << setw(25) << "1300\n";
	cout << "\n";
	cout << "3." << " Draft Horse"        << setw(27)   << "1500" << setw(25) << "2200\n";
	cout << "\n";

	cin >> "Enter type of horse <1-3>";
	cout << type



	system("PAUSE");
	return 0;
}
Last edited on
1
2
	cin >> "Enter type of horse <1-3>";
	cout << type

You mixed up cin and cout here.

As for associating a number with the type of horse, I'd recommend using an enum.
1
2
3
enum class Horse {
    lightRiding = 1, largeRiding, Draft
};

Then you can use the enum like so:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
switch( static_cast<Horse>( type ) )
{
case Horse::lightRiding:
    cout << "Light Riding Horse\n";
    break;

case Horse::largeRiding:
    cout << "Large Riding Horse\n";
    break;

case Horse::Draft:
    cout << "Draft Horse\n";
    break;

default:
    cout << "Invalid horse!\n";
}

Hello TheArk,

On lines 10 - 12 where did you define "type" is it an "int" or a "string"? Line 8 you should initialize all your variables. There are three ways to do this, I like lightRiding{ 0 }; it is called uniform initialization. This will eliminate any problems later when trying to use a variable that has no value. Actually it has a value, but it is garbage and does not work well.

Lines 32 and 33 the "cin" and "cout" are reversed. line 32 the "cin" goes to a variable not a constant string as you have. It should be cin >> type;.

integralfx has a good suggestion using the enum class, if you have learned about it.

I see you have a better understanding of "setw". Good job!

Hope that helps,

Andy
The program appears to be about a horse yard which'd have horses of various types: lightRiding, largeRiding, draft etc. So you could also consider inherting each of these types from a base type Horse: https://www.tutorialspoint.com/cplusplus/cpp_inheritance.htm
perfect, I appreciate the help!
Topic archived. No new replies allowed.