Vector trouble

I want to know how to add values to vectors using only user input. Any help?
I have three vectors relating to fish: The type, the size, and how many they want. I want the user to be able to enter these values and then the program to be able to repeat that information in a nice table format.
These are my vectors:
1
2
3
vector <string> fishType;
vector <int> fishSize;
vector <int> fishNum;

The instructions are to ask the user about the fish using a while loop, but I'm not sure what the condition should be.
For starters, how will the program know when the user is done entering all their data? If they tell you before they enter their data, you would use a for loop. If they tell you after they've entered their data by e.g. giving invalid data, you would use a while loop.

Show what you've got so far and then explain a specific thing you're stuck on.
Last edited on
Well, that's just it. I'm stuck on pretty much everything and my code isn't so good so far, but I'll give you what I got.



1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
#include <iostream>
#include <string>
#include <iomanip>
#include <vector>

using namespace std;

int main()
{
	cout<< "Shelby Teele \n"
		<<"C++ Tropical Fish Store\n"
		<<"This program will help you determine the tank\n"
		<<"size for your tropical fish.\n";
	
	vector <string> fishType;
		vector <int> fishSize;
		vector <int> fishNum;
		
		
		

		while() 
		
		{[code]

fishSize.push_back();
fishNum.push_back();


cout<< "What kind of fish would you like in your tank? \n";
cout<< "How long are they? \n";
cin >> fishSize;
cout<< "How many of them would you like? \n";
}



}[/code]

I left some things blank because I wasn't sure what should go there. The program isn't even close to done yet.
For one thing, the push_backs would go after the input, not before.

Start by getting all your input done inside the while loop - then we'll move on to the next part.

Also, I assume you noticed the extra [code][/code] inside your code that messed up the formatting ;)
Last edited on
Ok, thanks. And, yes, I accidentally pushed the source code format button twice and it did that. As soon as I'm done with the input, I'll post it here.
Oh, yeah. when I put in the cin chevrons, it comes up with the red squiggly line and says there is no operator that matches those operands. That's never happened before, and the cout chevrons are fine.
Did you declare the variables you're trying to cin to?
I'm trying to cin to the vectors themselves. Should I declare variables?

Also, I have more program. Is there an easier way to repeat that?

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
#include <iostream>
#include <string>
#include <iomanip>
#include <vector>

using namespace std;

int main()
{
	cout<< "Shelby Teele \n"
		<<"C++ Tropical Fish Store\n"
		<<"This program will help you determine the tank\n"
		<<"size for your tropical fish.\n";
	
	vector <string> fishType;
		vector <int> fishSize;
		vector <int> fishNum;
		
		
		

		while() 
		
		{
			string answer;
		

			cout<< "What kind of fish would you like in your tank? \n";
			cin>> fishType;
			cout<< "How long are they? \n";
			cin >> fishSize;
			cout<< "How many of them would you like? \n";
			cin>> fishNum;
			cout<< "Would you like to add another type of fish? yes/no \n";
			cin>> answer;
			if(answer == "yes");
			{
				cout<< "What kind of fish would you like in your tank? \n";
			cin>> fishType;
			cout<< "How long are they? \n";
			cin >> fishSize;
			cout<< "How many of them would you like? \n";
			cin>> fishNum;
			cout<< "Would you like to add another type of fish? yes/no \n";
			cin>> answer;
		}
			else
			{
			}
		fishSize.push_back();
		fishNum.push_back();


}
You need separate variables to cin into, and then you'll push_back those variables into the vector. That's why I mentioned that the input part happened first and the push_back part happened second.
Topic archived. No new replies allowed.