Stuck on this Code... Help please!

#include <iostream>
#include <string>
#include <fstream>
#include <cmath>
using namespace std;
int main ()
{
int creamer,milk,soda,water,cookies,chips,crackers;
int item;
creamer = 1;
milk = 2;
soda = 3;
water = 4;
cookies = 5;
chips = 6;
crackers = 7;
cout << "Please enter your item. " <<endl;
cin >> item;
if(item== 1 || item==2 || item==3 || item==4)
{
cout << "Go to isle 1. " << endl;
}
else if(item==5 || item==6 || item==7)
{
cout << "Go to isle 2. " << endl;
}
return 0;

}
Last edited on
So... What's your question? What are you stuck on?
(Please use code-tags)
Also, just by looking at your syntax, your strings should be int's.
Strings are for text-only.
Last edited on
Well Every time I try to compile it first I get an error, then if I press ignore, it will always cout "Go to isle 1"... Any sugestions? I think it has to do with the strings and characters, but I am very new to this.
Last edited on
Actually that was before... Then i changed it and now I just get an error message saying."cout exceeds 100"..?
Oh so I should have ints where it is string... And you think I can run it without error after that.
By the way thanks for helping man!
If there is any insight anyone wishes to give, please it would be appriciated. This is for my class.
... Your question really isn't that clear. Do you want users to exactly input what they want. For example:


Please enter you item:
Creamer


instead of using numbers?
Last edited on
Yes that is exactly what I want... Them to enter the item and then to cout out it's isle.
Try this:
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
#include <iostream>
#include <string>
#include <fstream>
#include <cmath>
using namespace std;
int main ()
{

string item;



cout << "Please enter your item. " <<endl;
cin >> item;
if (item.find ("Creamer") != string::npos)
{
 cout << "Go to aisle 1." << endl;
}
if (item.find("Milk") != string::npos)
{
  cout << "Go to aisle 1." << endl;
}
if (item.find("Soda") != string::npos)
{
 cout << "Go to aisle 1." << endl;
}
if (item.find("Water") != string::npos)
{
  cout << "Go to Aisle 1." << endl;
}
if (item.find ("Cookies") !=string::npos)
{
 cout << "Go to Aisle 2." << endl;
}
if (item.find ("Chips") !=string::npos)
{
cout << "Go to Aisle 2." << endl;

} if (item.find ("Crackers") != string::npos)
{
  cout << "Go to Aisle 2." << endl;
}
return 0;
}


It should work :)
Let me know if it helps you.
(Make sure when you run the program, you start each word off as a capital)
Last edited on
Yep runs fine... Thanks a billion man your awsome!!!
@Bradd
Try this..
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
// Shopping.cpp : Defines the entry point for the console application.
//

#include "stdafx.h"
#include <iostream>
#include <string>
#include <fstream>
#include <cmath>

using namespace std;

int main ()
{
	string ShoppingList[]={"","creamer","milk","soda","water","cookies","chips","crackers"};
	int buy,i;
	string item;
	
	cout << "Shopping List.." << endl<<endl;
	for(i=1;i<8;i++)
		cout << "\t" << ShoppingList[i]<<endl;
	cout << endl << "Please enter your item. " <<endl;
	cin >> item;
	buy=0;
	for (i=1;i<8;i++)
	{
		if (item==ShoppingList[i])
			buy=i;
	}

	if( item==ShoppingList[1] || item==ShoppingList[2] || item==ShoppingList[3]|| item==ShoppingList[4] )
	{
		cout << ShoppingList[buy] << ", is located in isle 1. " << endl;
	}
	else if(item==ShoppingList[5]|| item==ShoppingList[6] || item==ShoppingList[7] )
	{
		cout << ShoppingList[buy] << ", is located in isle 2. " << endl;
	}
	else
		cout << "We seem to be out of " << item << "." << endl;
	return 0;
}
What does including stdafx.h do?
Ignore it. It's a precompiled header thing that VS puts there if you don't start with a blank project.
Topic archived. No new replies allowed.