Looping nightmare
Hey guys,
I need a wee bit o' help with my game again. After every event, i want there to be al little interface where you can see your skills, items, etc. Ok, the functions to display are all sorted out, no problem there, but i want to create an interface, this
"1 - continue \n ";
"2 - view skills \n";
"3 - view items \n";
"4 - view compainions \n";
ok, now, what i did, is i created a while loop so that it would keep asking this until you press "1", to continue. The problem is, if i press a number other than 1, and than try to press one after that, nothing happens. Thus, i am trapped in the loop forever :eek:
Could someone help ? :D
Thanks :D
Mike
# 2 Re: Looping nightmare
It would be very helpgul for us if you could show us how exactly your loop is coded. We're experts, but not diviners;) (not yet, but we're working on it)
Danny at 2007-11-11 21:03:31 >

# 3 Re: Looping nightmare
cout << "1 - continue \n";
cout << "2 - view items \n";
cout << "3 - view skills \n";
cout << "4 - veiw companions \n";
cin >> view;
while ( view != 1 )
{
cout << "1 - continue \n";
cout << "2 - view items \n";
cout << "3 - view skills \n";
cout << "4 - veiw companions \n";
cin >> view;
switch ( view )
{
case '1' :
//nothing here, this is supposed to just make u continue on
break;
case '2' :
// function for viewing items
break;
case '3' :
//function for viewing skills
break;
case '4' :
// function for viewing compainions
break;
}
}
# 4 Re: Looping nightmare
first of all, I assume that view is of type int. In that case, your cases should contain the values 1,2, etc. not the quoted literals '1', '2' etc., which mean something quite different. Secondly, *always* provide a default case in your switches. This will enable you to trap bugs and invalid input. Finally, you want to use constants with meaningful names rather than bare integers.
Danny at 2007-11-11 21:05:40 >
