I have three inputs but I only get one output?

why am I only getting one output is it my for i loop. and it actualy prints out only the second input thats why I think the i++ is making it do 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
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
#include <iostream>
#include <string>
#include <limits>
using namespace std;


int main()

{
	// initialization of Variables
	string input1;
	string input2;
	string input3;
	string veg [3];
	string fruit [3];
	string dairy [3];

	//initialization
	veg [0] = "carrot";
	veg [1] = "broccoli";
	veg [2] = "tomato";
	 
	fruit [0] = "apple";
	fruit [1] = "orange";
	fruit [2] = "watermelon";

	dairy [0] = "milk";
	dairy [1] = "cheese";
	dairy [2] = "cream cheese";

	
		//if statement
		cout<<"Enter 3 Items"<<endl;
		cin>>input1;
		cin>>input2;
		cin>>input3;
		for(int i = 0;1 <3; i++)
		{
			if (input1 == veg [i])
				cout<<input1<<"Is a Vegetable" <<endl;
			else
				if(input1 == dairy[i])
					cout<<input1<<"Is a Dairy Product"<<endl;
				else
					if(input1 == fruit [i])
						cout<<input1<<"Is a Fruit Product"<<endl;
					else 
						if(input2 == veg [i])
						cout<<input2<<"Is a Vegetable"<<endl;
						else
							if(input2 == dairy[i])
								cout<<input2<<"Is a Dairy Product"<<endl;
							else
								if(input2 == fruit [i])
                                   cout<<input2<<"Is a Fruit Product"<<endl;
								else
									if(input3 == veg [i])
										cout<<input3<<"Is a Vegetable"<<endl;
									else
										if(input3 == dairy [i])
											cout<<input3<<"Is a Dairy Product"<<endl;
										else
										if(input3 == fruit [i])
											cout<<input3<<"Is a Fruit Product"<<endl;
										else cout<<"Unknown Item"<<endl;
										cout<<"press enter to continue"<<endl;
			system ("pause");

		return 0;	
		}
		


}


or do I need a nested loop somewhere? thanks for any help guys?
I can't help much, but I found one error. Line 37, for(int i = 0;1 <3; i++). I think you meant to put "i<3", not "1<3".
Alright, I figured out what is going on here. The for loop will end once it categorizes the first input. You need to create a new for loop for each input. For example:

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
for(int i = 0;i <3; i++)
{
     if input1...  //"..." are the rest of the code for the line
          .....;
     else
          if input1...
               .....;
           else
                if input1...
                     .....;
}
for(int i = 0;i <3; i++)
{
     if input2....
         ....;
     else
          if input2....
               ....;
           else
               if input2...
                    ....;
}

for(int i = 0;i <3; i++)
//same as above, but with imput3 
You can also add the code for the "unknown item" at the bottom of each for loop. This should work. Good luck!
I just started doing that I just need to reorganize cause ive been trying while loops at first and it would go on forever after the 1st item - as a matter of fact how do you keep a while loop from going on endlessly again? I forgot - AND THANKS A LOT KHRIS!!!
No problem..

Hmm, I'm still new to C++ so I'm not sure how to keep a while loop from going on endlessly. I hope someone else chimes in on this so I can learn also..
Read here for more explained instruction http://cplusplus.com/doc/tutorial/control/

-Mazeedy
Topic archived. No new replies allowed.