Question:
I'm having a small programming problem?
jayteemoney
2010-08-25 00:31:17 UTC
don't worry this isnt homework
But whats wrong with my if statements
code
string Dairy;
string List_a;
string Vegtables;
string List_b;
string Fruit;
string List_c;
string Unknown;
string Milk;
string List_d;
string Artichoke, Asparagus, Aubergene, Beans, Artichoke, Asparagus, Aubergene;
string Beans, Beet, Broccoli, Brussels_sprouts;
string Cabbage, Carrot, Cauliflower, Celeriac, Celery, Chard, Chicory;
string Collards, Corn, Cress, Cucumbers;
string Gourds;
string Jerusalem_Artichoke;
string Kales, Kohlrabi;
string Leek, Lettuce;
string Melons, Mushrooms;
string Okra, Onions;
string Parsnips, Peas, Peppers, Potatoes, Pumpkins;
string Radicchio, Radish, Rhubarb, Rutabaga;
string Shallots, Spinach, Squash, Swede, Sweetcorn, Sweet_potato;
string Tomatoes, Turnips;
string Yams;
string Orange;
string Apple;
string Grapes;
string Bannana;
string Cherry;
string item;
List_a = Vegtables;
List_d = Dairy;
List_c = Fruit;
item = Vegtables, Dairy, Fruit, Unknown;
Vegtables = Artichoke, Asparagus, Aubergene, Beans, Artichoke, Asparagus, Aubergene, Beans, Beet, Broccoli, Brussels_sprouts,
Cabbage, Carrot, Cauliflower, Celeriac, Celery, Chard, Chicory,Collards, Corn, Cress, Cucumbers, Gourds,Jerusalem_Artichoke,
Kales, Kohlrabi,Leek, Lettuce, Melons, Mushrooms, Okra, Onions,Parsnips, Peas, Peppers, Potatoes, Pumpkins,
Radicchio, Radish, Rhubarb, Rutabaga, Shallots, Spinach, Squash, Swede, Sweetcorn, Sweet_potato, Tomatoes, Turnips,Yams;
Dairy = Milk;
Fruit = Orange, Apple, Grapes, Bannana, Cherry;

int main;

{
cout<< "please Enter an Item";
cin >> item;
if(item == Vegtables)
cout<<"item will be sorted in";
else
if(item == Dairy)
cout<<"item will be stored in";
else
if(item == Fruit)
cout<<"item will be storedin";
else
if(item == Fruit)
cout<<"item will be stored in";
else
cout<<"item is Unknown";
return 0;
}

I know its a little long with the declarations but in the if statements I'm getting an error message with the == operator and also the cin>> operator the compiler doesn't recognize the >>operator
Four answers:
?
2010-08-25 00:35:16 UTC
I think there has to be a space either that or it should be if then start on a new line
oops
2010-08-25 01:12:11 UTC
There's plenty wrong, but it's not your if statements. I think you have major misunderstandings about how strings work and how lists work in c++. I would squash this project until you get a handle on that. The most basic error in your program is this:



int main;



main is a function, and needs some parenthesis for parameters, like this:



int main()

{

// this is the body of the main function

return 0;

}



Some other things:



List_a = Vegtables;



You cannot do this outside of a function, unless you do it as part of initialization, like this:



string List_a = Vegtables;



Next thing:



item = Vegtables, Dairy, Fruit, Unknown;



This would also need to go inside a function. But I am quite certain that it is not accomplishing what you think it's accomplishing. You probably want to learn about vectors: http://www.cplusplus.com/reference/stl/vector/vector/



But I honestly think that's too advanced for your level. Try a tutorial:

http://www.cplusplus.com/doc/tutorial/

http://www.youtube.com/watch?v=tyVhn0FWWB4&feature=PlayList&p=1D10C030FDCE7CE0&index=0&playnext=1



If you use that last one, it's a playlist on youtube. It starts very very basic, like finding and installing a compiler. You can skip the first couple of videos if you don't need help with that.
Jepe
2010-08-25 01:24:43 UTC
What language is this, I don't recognise it (so I probably don't know it). Perhaps it is only one = not ==, check the instructions or something, unless someone who knows answers this.
2016-12-19 15:59:45 UTC
You tousled your ifs. At one factor you do "else if" after which you turn to easily doing "if" and it messes up the hierarchy. additionally, your inequalities are tousled on a number of those conditionals.


This content was originally posted on Y! Answers, a Q&A website that shut down in 2021.
Loading...