Oct 11, 2011 at 6:24pm UTC
#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 Oct 11, 2011 at 6:51pm UTC
Oct 11, 2011 at 6:26pm UTC
So... What's your question? What are you stuck on?
(Please use code-tags)
Oct 11, 2011 at 6:29pm UTC
Also, just by looking at your syntax, your strings should be int's.
Strings are for text-only.
Last edited on Oct 11, 2011 at 6:30pm UTC
Oct 11, 2011 at 6:29pm UTC
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 Oct 11, 2011 at 6:40pm UTC
Oct 11, 2011 at 6:31pm UTC
Actually that was before... Then i changed it and now I just get an error message saying."cout exceeds 100"..?
Oct 11, 2011 at 6:34pm UTC
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!
Oct 11, 2011 at 6:53pm UTC
If there is any insight anyone wishes to give, please it would be appriciated. This is for my class.
Oct 11, 2011 at 6:56pm UTC
... 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 Oct 11, 2011 at 6:57pm UTC
Oct 11, 2011 at 7:00pm UTC
Yes that is exactly what I want... Them to enter the item and then to cout out it's isle.
Oct 11, 2011 at 7:09pm UTC
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 Oct 11, 2011 at 7:13pm UTC
Oct 11, 2011 at 7:15pm UTC
Yep runs fine... Thanks a billion man your awsome!!!
Oct 11, 2011 at 9:26pm UTC
What does including stdafx.h do?
Oct 11, 2011 at 10:13pm UTC
Ignore it. It's a precompiled header thing that VS puts there if you don't start with a blank project.