first, though it's not a fix, you can just put your cin.get before the return. It'll hit that either way.
Second, you don't have an else statement. so: if (i==1) { ... } else if (i == 2) { ... } what if I is 30? 50? -3266784? here's how we handle it: else { ... } On 2/9/2011 3:55 PM, Kristoffer Gustafsson wrote:
Hi.I thought that case only can be used on digit variables, such as int, double and such stuff.At least the tutorial I read said that.I tried both else if and if else before but got problems, now it sort of works. I don't get any output from my program, but I don' get any compiler errors at least.:)Here is my code. what can I havem made wrong? #include <iostream> using namespace std; int main() { cout <<"test"; string test; cin >>test; if (test=="try") { cout <<"nice"; cin.get(); } else if(test=="bad") { cout <<"that's bad!"; cin.get(); } return 0; } /Kristoffer ----- Original Message ----- *From:* Littlefield, Tyler <mailto:tyler@xxxxxxxxxxxxx> *To:* programmingblind@xxxxxxxxxxxxx <mailto:programmingblind@xxxxxxxxxxxxx> *Sent:* Wednesday, February 09, 2011 11:45 PM *Subject:* Re: If else sure. how are you going to translate cin >> direction to direction quickly? for that, you may as well just use if ... else if... else ... On 2/9/2011 3:42 PM, Sina Bahram wrote:So what? EnumDirection {north, south, east, west}; Or something akin to it. Can I use it now? **smile** Take care, Sina *From:*programmingblind-bounce@xxxxxxxxxxxxx <mailto:programmingblind-bounce@xxxxxxxxxxxxx> [mailto:programmingblind-bounce@xxxxxxxxxxxxx] *On Behalf Of *Christopher *Sent:* Wednesday, February 09, 2011 5:38 PM *To:* programmingblind@xxxxxxxxxxxxx <mailto:programmingblind@xxxxxxxxxxxxx> *Subject:* Re: If else It is not legal to use a switch/case statement on a non-integral type in C++. On 2/9/2011 2:30 PM, Sina Bahram wrote: Use a switch/case statement. Take care, Sina *From:*programmingblind-bounce@xxxxxxxxxxxxx <mailto:programmingblind-bounce@xxxxxxxxxxxxx> [mailto:programmingblind-bounce@xxxxxxxxxxxxx] *On Behalf Of *Littlefield, Tyler *Sent:* Wednesday, February 09, 2011 5:27 PM *To:* programmingblind@xxxxxxxxxxxxx <mailto:programmingblind@xxxxxxxxxxxxx> *Subject:* Re: If else if (direction == "north") { std::cout << "You go north." << std::endl; } else if (direction =="south") { std::cout << "You go south." << std::endl; } On 2/9/2011 3:07 PM, Kristoffer Gustafsson wrote: Hi. Now I've decided that I'll learn to do things both without goto, and with it. Because then I'll maybe discover that goto is bad:) I got one last code question today. I need so that my program can do more than one action. for example of writing a text adventure you want many. I've managed to put an if statement in my code. for example if direction=="south"; { cout<<"you go south."; } Now if I want to go north, how can I do that? I tried if else, but it only says "expected primary expression before else expected. Can you help me with this please? /Kristoffer --Thanks,Ty--Thanks, Ty
-- Thanks, Ty