In the first one, there are 2 problems:
while(choice<1 && choice>2)
means "Execute this block of code while
choice is less than 1 AND
choice is greater than 2"
Choice is never going to be both of those things, so the block is never go to be executed.
The second problem is that after
you have a semicolon
;
This ends the loop completely.
Here is an example of using a semicolon with a while loop:
1 2
|
while(count < 10)
count++;
|
The statement that ends with a semicolon straight after the while loop is executed while
count is less than 10. Because, in your case, there is a semicolon on its own, nothing will be executed (even when you do change && (meaning AND) to || (meaning OR)).
___________________________________________
In the second one, you give
userinput the value 0. However, the block of code after the
while() is only executed if
userinput is not equal to 0.
A solution to this is to either not give userinput a value (which is a bad idea, as it means the value is undefined and could be anything) or to give it another value (eg. 1), since the user enters a new value before anything is done to it.
An even better idea would be to change the loop from
1 2 3 4
|
while(userinput != 0)
{
...
}
|
to
1 2 3 4
|
do
{
...
} while(userinput != 0);
|
This means that the value of userinput is only checked after the loop has been executed for the first time (which is what you want).